Gmail Misinterpreting E-mail Headers

This might be a shot in the dark, but is anybody else having problems with Gmail misinterpreting headers in e-mails sent using PHP?

For some reason, yesterday morning, e-mails sent from my Linode VPS to my @gmail.com e-mail address had bits and pieces of their e-mail headers at the top of the body of the e-mail. Here's an example:

Delivered-To: REDACTED@gmail.com
Received: by 10.231.169.209 with SMTP id a17csp25276ibz;
        Thu, 26 Apr 2012 04:37:41 -0700 (PDT)
Received: by 10.182.42.103 with SMTP id n7mr1107452obl.5.1335440261352;
        Thu, 26 Apr 2012 04:37:41 -0700 (PDT)
Return-Path: <support@rundowncreator.com>
Received: from mail.rundowncreator.com (mail.rundowncreator.com. [96.126.127.160])
        by mx.google.com with ESMTP id zl5si331873obb.147.2012.04.26.04.37.41;
        Thu, 26 Apr 2012 04:37:41 -0700 (PDT)
Received-SPF: pass (google.com: domain of support@rundowncreator.com designates 96.126.127.160 as permitted sender) client-ip=96.126.127.160;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of support@rundowncreator.com designates 96.126.127.160 as permitted sender) smtp.mail=support@rundowncreator.com
Date: Thu, 26 Apr 2012 04:37:41 -0700 (PDT)
Message-Id: <4f993385.25a7b60a.4348.6509SMTPIN_ADDED@mx.google.com>
Received: by mail.rundowncreator.com (Postfix, from userid 33)
    id E719823AC7; Thu, 26 Apr 2012 04:37:40 -0700 (PDT)
To: support@rundowncreator.com
Subject: Automated Javascript Error Report
X-PHP-Originating-Script: 33:Toolkit_Functions.php
From: "Rundown Creator" <support@rundowncreator.com>

Message-Id: <20120426113740.E719823AC7@mail.rundowncreator.com>
Date: Thu, 26 Apr 2012 04:37:40 -0700 (PDT)

Type: Javascript
Error Message: Uncaught ReferenceError: toolkit_htmlspecialchars is not defined
File: https://rundowncreator.com/REDACTED/Header.js?r=72
Line: 12

Date: 4/26/12
Time: 4:37:40 AM PDT

IP Address: REDACTED
User Agent: REDACTED

UserID: REDACTED
Username: REDACTED</support@rundowncreator.com></support@rundowncreator.com>

Here's how e-mails were coming in before yesterday:

Delivered-To: REDACTED@gmail.com
Received: by 10.231.169.209 with SMTP id a17csp29513ibz;
        Tue, 24 Apr 2012 07:58:14 -0700 (PDT)
Received: by 10.60.29.39 with SMTP id g7mr9653444oeh.6.1335278066709;
        Tue, 24 Apr 2012 07:34:26 -0700 (PDT)
Return-Path: <support@rundowncreator.com>
Received: from mail.rundowncreator.com (mail.rundowncreator.com. [96.126.127.160])
        by mx.google.com with ESMTP id qx5si10474228obb.114.2012.04.24.07.34.26;
        Tue, 24 Apr 2012 07:34:26 -0700 (PDT)
Received-SPF: pass (google.com: domain of support@rundowncreator.com designates 96.126.127.160 as permitted sender) client-ip=96.126.127.160;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of support@rundowncreator.com designates 96.126.127.160 as permitted sender) smtp.mail=support@rundowncreator.com
Received: by mail.rundowncreator.com (Postfix, from userid 33)
    id 93C3F23EA7; Tue, 24 Apr 2012 07:34:26 -0700 (PDT)
To: support@rundowncreator.com
Subject: Automated Javascript Error Report
X-PHP-Originating-Script: 33:Toolkit_Functions.php
From: "Rundown Creator" <support@rundowncreator.com>
Message-Id: <20120424143426.93C3F23EA7@mail.rundowncreator.com>
Date: Tue, 24 Apr 2012 07:34:26 -0700 (PDT)

Type: Javascript
Error Message: b.item[0].parentNode is null
File: https://www.rundowncreator.com/REDACTED/jQueryUI.js?r=70
Line: 54

Date: 4/24/12
Time: 7:34:26 AM PDT

IP Address: REDACTED
User Agent: REDACTED

UserID: REDACTED
Username: REDACTED</support@rundowncreator.com></support@rundowncreator.com>

I've been using the same PHP function to send e-mails for some time:

function toolkit_mail($To, $From_Name, $From_EmailAddress, $Subject, $Message, $CC=false){
    $Header="From: \"$From_Name\" <$From_EmailAddress>\r\n";
    if($CC) $Header.="CC: $CC\r\n";
    mail($To, $Subject, $Message, $Header, "-f$From_EmailAddress");
}

I haven't changed it recently, so I'm not sure what is causing the issue. Any ideas?

2 Replies

Given the headers as shown there's an erroneous extra line between From: and Message-ID: which is thus terminating the headers. You don't say which "bits and pieces" of the headers are showing up, but if it's the Message-ID and Date headers I think GMail is doing the right thing.

If I had to guess it would be that you're allowing Message-ID and Date to be added for you (either by the PHP layer or your MTA), so it seems plausible that the headers you are constructing have an extra line at the end to which the automatic headers get appended.

I can't necessarily explain why it suddenly started happening but one thing I'm curious about in your code is whether you're sure you should be using "\r\n" to terminate your own headers? I'm not familiar with PHP's mail functions (assuming mail() isn't from a third party library) but in many cases such libraries expect normal newline termination (e.g., just "\n") at the code layer and they turn it into the proper CRLF during transmission.

If there's any way to get a string version of your message without actually transmitting you could check what's going out versus what GMail is showing as received, but my inclination is to believe that the extra line is being added pre-transmission somewhere.

– David

Yeah, the bits and pieces I was referring to are the From: and Message-ID: headers. Oddly, e-mails sent a few days ago didn't have the extra space. In either case, I tried removing the "\r" like you said and it fixed the problem. Thanks!

Many of the examples in the PHP documentation for mail() use "\r\n", and having it in there worked for so long, so I wonder what caused things to break all of a sudden…

Perhaps the Gmail team tweaked something on their end, because the same e-mail sent to an @yahoo.com e-mail address worked just fine.

Oh well. Works now!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct