|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35906 Date Header produces non-RFC date (works with PHP 5.1)
Submitted: 2006-01-05 16:27 UTC Modified: 2006-01-06 09:11 UTC
From: brian at macserve dot net Assigned:
Status: Closed Package: Mail related
PHP Version: 4.4.1 OS:
Private report: No CVE-ID: None
 [2006-01-05 16:27 UTC] brian at macserve dot net
The Date header that is generated in the mail() command is not RFC compliant in that it generates 2 spaces right before the day of the month, when there should only be one.

This trips spam filters that are looking for sloppy programming by spammers.

Interstingly, date('r') produces a correctly spaced date:
Thu, 05 Jan 2006 08:51:13 -0600

Probably because the day of month is padded.

line 716 from 4.4.1's sendmail.c:
sprintf(header_buffer, "Date: %s, %02d %s %04d %02d:%02d:%02d %s%02d%02d\r\n",

Looks like this was fixed in the 5.x branch by changing this to effectively use: date('r') in response to bug # 29334

line 706:
char *dt = php_format_date("r", 1, tNow, 1 TSRMLS_CC);
sprintf(header_buffer, "Date: %s\r\n", dt);

Reproduce code:
$toAddress = '';
$fromAddress = '';
$extraParams = '-f'.$fromAddress;
$subj = 'Test Date Hdr';
$emailMsg = 'Test Message';
echo mail($toAddress, $subj, $emailMsg, '', $extraParams);

Expected result:
Date: Thu, 5 Jan 2006 08:51:03 -0600 (CST)

Actual result:
Date: Thu,  5 Jan 2006 08:51:03 -0600 (CST)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-05 21:33 UTC]
Assigned to the maintainer.
 [2006-01-05 23:15 UTC]
I am not the maintainer of Win32 mail code, I don't even have windows so I can't test this. This is not a problem on any other OS than Windows either, as that doesn't use the sendmail.c code.
 [2006-01-06 01:36 UTC]
Please try using this CVS snapshot:
For Windows:

I just committed a fix for this. Please test in about 6 hours.
 [2006-01-06 01:59 UTC] brian at macserve dot net
I don't have Windows either.

I was seeing this under Mac OS 10.3.9 (Postfix/sendmail), so looking at the code and the bug fixes told me it was still around.

I guess it's Postfix fixup that is the culprit here.

2 Questions:

1. What logic was applied that determined that *nix PHP can't  utilize the SMTP engine that is present in Win32PHP?

2. For consistency sake, wouldn't it be better to have the code for outputting messages across the same platforms do the same thing regardless of final SMTP chain injection method?

As in, the same code that is used to detect/add Date: headers (in the proper format) should be used on messages submitted through mail() on ALL platforms.

This should have zero effect on *nix platforms as the "sendmail" emulators shouldn't add another Date header, if already present.

 [2006-01-06 02:13 UTC]
I don't know what you're talking about, but the sendmail.c you pointed at is only used within Windows. And that part is now fixed.
 [2006-01-06 03:05 UTC] brian at macserve dot net
I understand that this is now fixed under Windows.

My extended comments were stating that the the real culprit for MY particular issue with this was being caused by Postfix.

Since the mail() command calls the "sendmail" binary to submit a new email message, it's not PHP's fault that Postfix is creating a non-RFC compliant Date header.

I THOUGHT is was PHP's fault and investigating it brought the issue for Windows mail() code to light.

My other questions still stand as to improving the intelligence of the mail() command under non-Windows systems so as to create as close to parity in calling mail() across all platforms.

Why does the Windows code only get the Date header checking code, when the non-Windows code would benefit just as greatly.
 [2006-01-06 09:11 UTC]
There is often no MTA available on Windows, and definitely not a "sendmail" binary to call. As setting mail headers is hard we rather see the "sendmail" binaries do this, instead of having to create our own fully fledged mail sending code. However because Windows is so crippled we have to have some simple code there that allows users to send mail, on Windows users have to specify a real SMTP server in their config if they want to send mail.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Jul 23 20:01:23 2021 UTC