ID: 48620
Comment by: shahar dot e at zend dot com
Reported By: shahar dot e at zend dot com
Status: Open
Bug Type: Mail related
Operating System: Mac OS X 10.5
PHP Version: 5.3.0RC4
New Comment:
I used this patch to fix it (not sure if it's the most suitable way):
--- ext/standard/mail.c.orig 2009-06-20 22:25:10.000000000 +0300
+++ ext/standard/mail.c 2009-06-20 22:29:52.000000000 +0300
@@ -241,7 +241,10 @@
php_basename(tmp, strlen(tmp), NULL, 0,&f, &f_len
TSRMLS_CC);
if (headers != NULL) {
- spprintf(&hdr, 0,
"%s\r\nX-PHP-Originating-Script: %ld:%s\n", headers, php_getuid(), f);
+ spprintf(&hdr, 0,
"%s%sX-PHP-Originating-Script: %ld:%s\n",
+ headers,
+ (headers[strlen(headers) - 1] == '\n' ?
"" : "\r\n"),
+ php_getuid(), f);
} else {
spprintf(&hdr, 0, "X-PHP-Originating-Script:
%ld:%s\n", php_getuid(), f);
}
Previous Comments:
------------------------------------------------------------------------
[2009-06-20 17:49:14] shahar dot e at zend dot com
Description:
------------
It is very possible for a developer to use code like in the attached
reproduction code to send an e-mail. However, when mail.add_x_header is
On, using this code will cause the X-PHP-Originating-Script to show in
the message body instead of as a header.
This is because mail() assumes the $headers parameter is a string which
does not end with a trailing CRLF - while in practice it very well may
be (it works well when mail.add_x_header is Off).
Reproduce code:
---------------
<?php
$headers = array(
'X-Foo' => 'bar',
'From' => '[email protected]',
'Priority' => 'Urgent'
);
$hdrStr = '';
foreach($headers as $k => $v) {
$hdrStr .= "$k: $v\r\n";
}
mail('[email protected]',
'Testing add_x_header',
'This is a test',
$hdrStr);
Expected result:
----------------
Mail to look like:
To: [email protected]
Subject: Testing add_x_header
X-Foo: bar
From: [email protected]
Priority: Urgent
Date: Sat, 20 Jun 2009 20:37:34 +0300 (IDT)
X-PHP-Originating-Script: 503:mailtest.php
This is a test
Actual result:
--------------
To: [email protected]
Subject: Testing add_x_header
X-Foo: bar
From: [email protected]
Priority: Urgent
Date: Sat, 20 Jun 2009 20:37:34 +0300 (IDT)
X-PHP-Originating-Script: 503:mailtest.php
This is a test
* this is how I receive the e-mail in GMail - perhaps there is some
header mangling but you get the point
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48620&edit=1