php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20340 mail() incorrectly strips multiple \r\n
Submitted: 2002-11-10 11:04 UTC Modified: 2002-11-12 01:56 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: _ at mrmachine dot net Assigned:
Status: Not a bug Package: Mail related
PHP Version: 4CVS-2002-11-10 OS: Windows XP SP1
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: _ at mrmachine dot net
New email:
PHP Version: OS:

 

 [2002-11-10 11:04 UTC] _ at mrmachine dot net
tested on 4.3pre2 and 4.3-snapshot (2002-11-10).

php4/win32/sendmail.c contains:

/* This pattern removes \r\n from the start of the string,
 * \r\n from the end of the string and also makes sure every line
 * is only wrapped with a single \r\n (thus reduces multiple
 * occurences of \r\n between lines to a single \r\n) */
#define PHP_WIN32_MAIL_RMVDBL_PATTERN   "/^\r\n|(\r\n)+$/m"
#define PHP_WIN32_MAIL_RMVDBL_REPLACE   ""

i'm not certain if the applicable specification(s) require that there be NO multiple occurences of \r\n in a mime message, but this addition has broken compatibility with outlook express clients at the very least, which seems to depend on multiple \r\n to separate content blocks.

it will also unecessarily alter valid mail content, and therefore i believe \r\n should only be stripped from the beginning and end of the message, if at all.

example code:

--cut--
$headers  = 'From: _@mrmachine.net' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: multipart/mixed;' . "\r\n";
$headers .= '	boundary="703c1875a9605c5619dd34f7642dcad8"' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 7bit' . "\r\n\r\n";

$headers .= 'This is a multi-part message in MIME format.' . "\r\n\r\n";

$headers .= '--703c1875a9605c5619dd34f7642dcad8' . "\r\n";
$headers .= 'Content-Type: text/html;' . "\r\n";
$headers .= '	charset="iso-8859-1"' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 7bit' . "\r\n\r\n";

$headers .= '<pre>' . "\r\n";
$headers .= 'test paragraph 1' . "\r\n\r\n";

$headers .= 'test paragraph 2' . "\r\n";
$headers .= '</pre>' . "\r\n\r\n";

$headers .= '--703c1875a9605c5619dd34f7642dcad8--' . "\r\n";

mail('_@mrmachine.net', 'test', null, $headers);
--cut--

the above code will deliver a seemingly empty email. if the message source is viewed, you will find that even had the content been displayed, it would not be as the sender had intended (no blank line between paragraphs):

--cut--
Content-Transfer-Encoding: 7bit
<pre>
test paragraph 1
test paragraph 2
</pre>
--703c1875a9605c5619dd34f7642dcad8--
--cut--

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-10 11:10 UTC] _ at mrmachine dot net
the bug system seems to have entered an erroneous carriage return on line 7 of my example code.
 [2002-11-10 11:29 UTC] richard@php.net
You should not put the entirety of your mail in the headers arg. Put the headers in the headers, and the body in the body. Multiple instances of CRLF in the headers would indicate the separation between headers and body of the mail.
 [2002-11-10 19:01 UTC] _ at mrmachine dot net
this bug is not bogus, and it is not invalid to put content inside the headers. in fact, it is required for example when attaching a file. see my extended code example which does as you suggest, with identical results (no body or attachment shows up in outlook express).

--cut--
$headers  = 'From: tai_lee@mrmachine.net' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: multipart/mixed;' . "\r\n";
$headers .= '	boundary="74233bf674edd3ebd68da956062cd872"' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 7bit' . "\r\n\r\n";

$headers .= 'This is a multi-part message in MIME format.' . "\r\n\r\n";

$headers .= '--68a7876fa15399a2f9ea92cf7571bdd6' . "\r\n";
$headers .= 'Content-Type: image/gif;' . "\r\n";
$headers .= '	name="arrows.gif"' . "\r\n";
$headers .= 'Content-Transfer-Encoding: base64' . "\r\n";
$headers .= 'Content-Disposition: attachment;' . "\r\n";
$headers .= '	filename="arrows.gif"' . "\r\n\r\n";

$headers .= 'R0lGODlhCwAHAMQVAAEBAfz//QAABAIAAQEBAP/+/AABBQEBA/7+/gIAA//9/gACAQEAAv///f7/' . "\r\n";
$headers .= '///+/wAAAgEAAAABAP///wAAAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEA' . "\r\n";
$headers .= 'ABUALAAAAAALAAcAAAU6YMRQUkJKUFVRgRQhS/IIaTQ9S+NQT+OSDoVEMSEgCgOKYyKZTHiOg6sR' . "\r\n";
$headers .= 'oUwgPGzFwABAIhIKJVUJAQA7' . "\r\n\r\n";

$headers .= '--68a7876fa15399a2f9ea92cf7571bdd6--' . "\r\n";

$body  = '<pre>' . "\r\n";
$body .= 'test paragraph 1' . "\r\n\r\n";

$body .= 'test paragraph 2' . "\r\n";
$body .= '</pre>' . "\r\n\r\n";

mail('_@mrmachine.net', 'test', $body, $headers);
--cut--

also if i were not to use $headers for actual content, how could i specify a text version and an html version of the email?

there is no reason not to allow people to create an entire (valid) mime format email and send it through the headers.
 [2002-11-10 19:17 UTC] _ at mrmachine dot net
i tried putting all headers that contain content into the $body, and that seems to fool it.

i still believe however, that headers should not be manipulated in that way. it's a hack to have to put half your mime headers in the body and half in the headers.

--cut--
$headers  = 'From: _@mrmachine.net' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: multipart/mixed;' . "\r\n";
$headers .= '	boundary="a646837d88fd9ce72caf49ee0efa4c0e"' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 7bit' . "\r\n\r\n";

$headers .= 'This is a multi-part message in MIME format.' . "\r\n\r\n";

$body  = '--a646837d88fd9ce72caf49ee0efa4c0e' . "\r\n";
$body .= 'Content-Type: text/html;' . "\r\n";
$body .= '	charset="iso-8859-1"' . "\r\n";
$body .= 'Content-Transfer-Encoding: 7bit' . "\r\n\r\n";

$body .= 'test' . "\r\n\r\n";

$body .= '--a646837d88fd9ce72caf49ee0efa4c0e' . "\r\n";
$body .= 'Content-Type: image/gif;' . "\r\n";
$body .= '	name="arrows.gif"' . "\r\n";
$body .= 'Content-Transfer-Encoding: base64' . "\r\n";
$body .= 'Content-Disposition: attachment;' . "\r\n";
$body .= '	filename="arrows.gif"' . "\r\n\r\n";

$body .= 'R0lGODlhCwAHAMQVAAEBAfz//QAABAIAAQEBAP/+/AABBQEBA/7+/gIAA//9/gACAQEAAv///f7/' . "\r\n";
$body .= '///+/wAAAgEAAAABAP///wAAAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEA' . "\r\n";
$body .= 'ABUALAAAAAALAAcAAAU6YMRQUkJKUFVRgRQhS/IIaTQ9S+NQT+OSDoVEMSEgCgOKYyKZTHiOg6sR' . "\r\n";
$body .= 'oUwgPGzFwABAIhIKJVUJAQA7' . "\r\n\r\n";

$body .= '--a646837d88fd9ce72caf49ee0efa4c0e--' . "\r\n";

mail('_@mrmachine.net', 'test', $body, $headers);
--cut--
 [2002-11-12 01:56 UTC] derick@php.net
The MIME-headers in the BODY of your mail are part of the BODY part, and not of the headers. Please refer to RFC822 [1] and RFC 1341 [2]

[1] http://rfc.sunsite.dk/rfc/rfc821.html
[2] http://rfc.sunsite.dk/rfc/rfc1341.html
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 18:01:31 2024 UTC