PHP mail() And Gmail – A Warning on Headers
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!
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.
Desde México un agradecimiento, ya llevábamos bastante tiempo investigando que pasaba
Thanks, I hope that fixes it. What’s interesting is that I have a gmail account and two Google Apps accounts. All the emails that I sent to myself were properly formatted. It was only some of my readers who were seeing the HTML code. Odd.
But ultimately who cares. I think this fixes it for everyone.
thanx man