|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 08:00:02 2025 UTC |
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.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.