Sending HTML/Plain text Emails

Reply

Join Date: Feb 2004
Posts: 2
Reputation: lunac is an unknown quantity at this point 
Solved Threads: 0
lunac lunac is offline Offline
Newbie Poster

Sending HTML/Plain text Emails

 
0
  #1
Feb 7th, 2004
I'm trying to send an html/plain text email for an invoice program I am writing. I really want the html message because it offers better layout options for invoicing and some features to help my customers with their payments. However, some email clients don't work with html email -- especially web mail. So I need the alternative plain text email in those cases.

I found this script at http://snipe.net/geek/toolz/htmlmail.php. It's similar to a script at http://www.zend.com/zend/trick/html-email.php. I think the main difference is how they encode the message. I found the message encoding in the zend article doesn't work for me at all. The snipe script was only sending one email with all the headers in the email.

I played around with the line breaks and was able to finally get two emails (plain/html). I can switch between and view each one. However the header information for each type is still showing in the email.

Does anyone know what I'm doing wrong?

[php]
$boundary = "nextPart";

$headers = "FROM: me@fromme.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/alternative; boundary = $boundary\r\n\r\n";
$headers .= "This is a MIME encoded message.\r\n\r\n";

//text version
$headers .= "--$boundary\n
Content-Type: text/plain; charset=ISO_8859-1\r\n
Content-Transfer_Encoding: 7bit\r\n\r\n";
$headers .= "This is the plain version\r\n\r\n";

// html version
$headers .= "--$boundary\r\n
Content-Type: text/html; charset=ISO_8859-1\r\n
Content-Transfer_Encoding: 7bit\r\n\r\n";
$headers .= "This is the <b>HTML</b> version";

mail("me@myemail.com", "An HTML Message", "", $headers);
[/php]
Reply With Quote Quick reply to this message  
Join Date: Feb 2004
Posts: 2
Reputation: lunac is an unknown quantity at this point 
Solved Threads: 0
lunac lunac is offline Offline
Newbie Poster

Re: Sending HTML/Plain text Emails

 
0
  #2
Feb 7th, 2004
Success!

Those \r\n lines are SO picky.

This is what I got to work
[php]
$boundary = "nextPart";

$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: Me <sales@mysite.com>\r\n";
$headers .= "Content-Type: multipart/alternative; boundary = $boundary\r\n";

//text version
$headers .= "\n--$boundary\n"; // beginning \n added to separate previous content
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "This is the plain version";

//html version
$headers .= "\n--$boundary\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "This is the <b>HTML</b> version";

mail("me@mymail@mac.com", "An HTML Message", "", $headers);
[/php]

Hopes this helps anyone else who's had problems with html/plain email.

Additional note:
The email message that I send (both versions) contained ":" . This caused my email not to show up in Mac OS X.3 Mail.app, although it showed properly in Entourage. Maybe it was because I sent my message in the headers part -- I'm not sure. Anyway, removing the ":" fixed that problem too.
---
lunac
it's a crazy world
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 2
Reputation: joebaileyorg is an unknown quantity at this point 
Solved Threads: 0
joebaileyorg joebaileyorg is offline Offline
Newbie Poster

Re: Sending HTML/Plain text Emails

 
0
  #3
Apr 3rd, 2008
Lunac,

Thanks. I'm on a project now and the code fit nicely in.

Only issue I had, that doesn't relate to you, but Outlook 2007 is now sending HTML files to the junk folder if they have images.
<snipped>
Last edited by peter_budo; Apr 5th, 2008 at 1:26 pm. Reason: Keep It Spam-Free - Do not spam, advertise, plug your website, or engage in any other type of self promotion.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 66
Reputation: silviuks is an unknown quantity at this point 
Solved Threads: 11
silviuks silviuks is offline Offline
Junior Poster in Training

Re: Sending HTML/Plain text Emails

 
0
  #4
Apr 4th, 2008
maybe because your server is on the black list ...
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 2
Reputation: joebaileyorg is an unknown quantity at this point 
Solved Threads: 0
joebaileyorg joebaileyorg is offline Offline
Newbie Poster

Re: Sending HTML/Plain text Emails

 
0
  #5
Apr 4th, 2008
Good point. I worked on testing it a lot last night. From what I can tell, the site isn't black listed, but had more to do with the content. I haven't quite resolved everything yet, but here's what I have:

Email 1
Subject: Contact from x website
-result: non-spam
Body: contains a small amount of html, not much really just contact info
-result: non-spam
-If I add a graphic, no effect
-If I add a graphic and put a link around it, it is considered spam.

Email 2:
Subject: x wants you to know about this promotion
-result: spam
Body: not much just a graphic for now and minimul html
-result: spam all around
delivers in junk mail
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC