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 (
rn) 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.0rn";
This, however, will fix the problem and show up in gmail just fine:
$headers = "MIME-Version: 1.0n";
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!