php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47983 mixed LF and CRLF line endings in mail()
Submitted: 2009-04-16 09:05 UTC Modified: 2020-04-02 12:53 UTC
Votes:11
Avg. Score:4.8 ± 0.6
Reproduced:9 of 9 (100.0%)
Same Version:1 (11.1%)
Same OS:8 (88.9%)
From: hannibal at astral dot lodz dot pl Assigned: cmb (profile)
Status: Closed Package: Mail related
PHP Version: 5.2.9 OS: Linux
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: hannibal at astral dot lodz dot pl
New email:
PHP Version: OS:

 

 [2009-04-16 09:05 UTC] hannibal at astral dot lodz dot pl
Description:
------------
Diffrent parts of mail function use LF some CRLF. This cause headers
to have mixed LF & CRLF endings. This can casue in some situation
broken mail delivery. PLEASE do not tell this is MTA problem. This is
also your concer to PROVIDE MTA standard compilant headers or at
least do this in consistent way.

Details:
ext/standard/mail.c (PHP 5.2.9) line 147
SKIP_LONG_HEADER_SEP(to_r, i);

This code assume that user provide CRLF line ending. If user provide
LF only, it is replace by spaces - so it cannot be used.


ext/standard/mail.c (PHP 5.2.9) line 273-278
fprintf(sendmail, "To: %s\n", to);
fprintf(sendmail, "Subject: %s\n", subject);
if (headers != NULL) {
   fprintf(sendmail, "%s\n", headers);
}
fprintf(sendmail, "\n%s\n", message);

This cleanly show that headers added automatially by PHP are always
ended by LF only.

In case, where subject is multline, headers always have mixed CRLF
and LF. This cause Postfix to left CR in header lines that have it.
It can cause probles where buggy Qmail is recipent, it replaces alone
CR to empty line, which causes premature end of headers in recipent
mail program. Again this is also YOUR PROBLEM, MTA must only properly
handling RFC compilant data - when other is sended, behaviour can be
undefined.

There is a couple methods to fix it, more or less properly.
1. Add "\r" to fprintf - RFC compilant but probably broke many apps
which use LF only header endings.
2. Add support to LF ending to SKIP_LONG_HEADER_SEP - also quite
easy, but not necessery best.
3. Add prameter to mail function in which user provide desired EOL -
best some enum (LEGACY - current buggy, CRLF - RFC compilant, LF -
unix compilant)
4. Configuration parameter whith same values as above.


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-23 21:12 UTC] jani@php.net
-Package: Feature/Change Request +Package: Mail related
 [2016-08-02 19:08 UTC] anrdaemon at freemail dot ru
Using a wrapper along the lines of

/usr/bin/tee -a "/tmp/sendmail.log" | /usr/sbin/sendmail "$@"

it is easy to prove that PHP, indeed, inconsistent in its documentation and internal use of mail handling.
In other words, contrary to the http://php.net/manual/en/function.mail.php additional headers must be provided with LF separation. Even on Windows.
 [2020-04-02 11:09 UTC] cmb@php.net
-Summary: schizophrenic behaviour of adding EOL indicator in mail() +Summary: mixed LF and CRLF line endings in mail() -Status: Open +Status: Verified -Type: Feature/Change Request +Type: Bug -Assigned To: +Assigned To: cmb
 [2020-04-02 11:09 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #47983: mixed LF and CRLF line endings in mail()
On GitHub:  https://github.com/php/php-src/pull/5338
Patch:      https://github.com/php/php-src/pull/5338.patch
 [2020-04-02 12:51 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6983ae751cd301886c966b84367fc7aaa1273b2d
Log: Fix #47983: mixed LF and CRLF line endings in mail()
 [2020-04-02 12:51 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2020-04-02 12:53 UTC] cmb@php.net
Will be fixed in PHP 8 only for BC reasons.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC