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?
$boundary = "nextPart"; $headers = "FROM: [email]email@example.com[/email]\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("firstname.lastname@example.org", "An HTML Message", "", $headers);