| | |
Sending HTML/Plain text Emails
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2004
Posts: 2
Reputation:
Solved Threads: 0
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]
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]
•
•
Join Date: Feb 2004
Posts: 2
Reputation:
Solved Threads: 0
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.
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
lunac
it's a crazy world
•
•
Join Date: Apr 2008
Posts: 2
Reputation:
Solved Threads: 0
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>
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.
•
•
Join Date: Apr 2008
Posts: 2
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- Sending HTML emails from Excel using Macro (Windows Software)
- Sending html emails (PHP)
- Sending invitation emails (Advertising Sales Strategies)
- vBulletin HTML emails (Growing an Online Community)
- Display and edit HTML\Plain text (C#)
Other Threads in the PHP Forum
- Previous Thread: value doesnt get carried to next page
- Next Thread: <textarea> readonly
| Thread Tools | Search this Thread |
5.2.10 action apache api array beginner beneath binary broken cakephp checkbox class classes cms code cron curl database date destroy display dynamic echo echo$_get[x]changingitintovariable... email encode error fcc file files folder form forms function functions google header howtowriteathesis href htaccess html image images include insert ip javascript joomla limit link local login mail memberships menu mlm mod_rewrite multiple multipletables mysql mysqlquery neutrality oop open passwords paypal pdf php provider query radio random record remote rss script search server sessions sockets source space sql strip_tags syntax system table template thesishelp tutorial update upload url validator variable video voteup web window.onbeforeunload=closeme; youtube





