PHP mail() And Gmail - A Warning on Headers
Posted on December 7th, 2005 in Web Development, Linux, Fixit, Code |
Today, out of nowhere, we started receiving reports that HTML email the gdiapers.com site was sending were showing up as just that: HTML code and not much else. Running a few tests confirmed these reports… but only in my gmail account. We went back and checked the reports and sure enough - they were all coming from gmail users.
After some tinkering and futzing around we realized that the Windows line breaks that we had after the headers (\r\n) were the problem. Here’s an example:
This will show up as two line breaks in gmail and trash your HTML formatting:
$headers = "MIME-Version: 1.0\r\n";
This, however, will fix the problem and show up in gmail just fine:
$headers = "MIME-Version: 1.0\n";
I’m sure if you were sending mail from a Windows server this may not be the case, but for those on a Unix box, just stick with \n. Google will thank you by displaying your HTML email the way it was meant to be displayed - without raw code!
9 Responses
Thanks man. Very helpful.
Thanks, this save me a while
You’re the man! Thanks for the Christman gift!!
Thank you
Worked just fine.
Thank you! You have completly resolved my problem
Thanks a lot
You just saved my ass, thank you sir!
but is it cause any problem for yahoo or hotmail user?
Thank you, Just what i need.