php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45305 From Header Not Parsed Correctly
Submitted: 2008-06-19 00:42 UTC Modified: 2008-07-01 09:54 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: php at info-svc dot com Assigned:
Status: Not a bug Package: Mail related
PHP Version: 5.2.6 OS: Windows Server 2003 SP2
Private report: No CVE-ID: None
 [2008-06-19 00:42 UTC] php at info-svc dot com
Description:
------------
PHP fails to parse the From: header in mail()'s additional_headers parameter when all of the following conditions exist:

* Header is in the form of From: Name <address>
* Script does not call ini_set('sendmail_from')
* php.ini does not configure sendmail_from

As the test server is using the localhost smtp service I can't see the smtp session using Network Monitor.  The error returned by PHP is shown below.  If there is a way for me to show you the bad MAIL TO command just let me know how.

Reproduce code:
---------------
ini_set('display_errors', TRUE);
echo 'Sending message 1<br />';
mail('nospam@info-svc.com', 'Test Message1', 'Does the From header work at all?', 'From: miqrogroove@hotmail.com');
echo 'Sending message 2<br />';
mail('nospam@info-svc.com', 'Test Message2', 'Does the From header work at all?', 'From: Robert Chapin <miqrogroove@hotmail.com>');
ini_set('sendmail_from', NULL);
echo 'Sending message 3<br />';
mail('nospam@info-svc.com', 'Test Message3', 'Does the From header work at all?', 'From: miqrogroove@hotmail.com');
echo 'Sending message 4<br />';
mail('nospam@info-svc.com', 'Test Message4', 'Does the From header work at all?', 'From: Robert Chapin <miqrogroove@hotmail.com>');


Expected result:
----------------
Sending message 1
Sending message 2
Sending message 3
Sending message 4

Actual result:
--------------
Sending message 1
Sending message 2

Warning: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address in test.php on line 5
Sending message 3
Sending message 4


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-19 01:03 UTC] php at info-svc dot com
Notice the SMTP error can never be reproduced if the following statement comes before mail()

ini_set('sendmail_from', ini_get('sendmail_from'));

This is a good workaround until the bug is fixed.
 [2008-06-19 01:50 UTC] php at info-svc dot com
I found the advanced logging options :)  Here is an excerpt:

#Fields: time c-ip cs-method cs-uri-query 
01:44:24 192.168.4.8 MAIL +FROM:<miqrogroove@hotmail.com>
01:44:24 192.168.4.8 RCPT +TO:<nospam@info-svc.com>

01:44:24 192.168.4.8 MAIL +FROM:<Robert+Chapin+<miqrogroove@hotmail.com>>

01:44:24 192.168.4.8 MAIL +FROM:<>
01:44:24 192.168.4.8 RCPT +TO:<nospam@info-svc.com>

01:44:24 192.168.4.8 MAIL +FROM:<>
01:44:24 192.168.4.8 RCPT +TO:<nospam@info-svc.com>
 [2008-06-19 02:38 UTC] php at info-svc dot com
sendmail.c @ 265

		/* Real offset is memaddress from the original headers + difference of
		 * string found in the lowercase headrs + 5 characters to jump over   
		 * the from: */
		pos1 = headers + (pos1 - headers_lc) + 5;
		if (NULL == (pos2 = strstr(pos1, "\r\n"))) {
			RPath = estrndup(pos1, strlen(pos1));

This assumes there is always a valid addr-spec sandwiched between "\nFrom:" and "\r\n" inside the additional_headers value.  But in RFC 2822 the From header is defined as mailbox-list.  So, the RPath assignment in sendmail.c needs to detect both name-addr and addr-spec formats in the From header.
 [2008-06-25 18:19 UTC] php at info-svc dot com
Related research:
#28038
#32600
#33507
#37073
#43730
#45249
 [2008-07-01 09:54 UTC] jani@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC