Bug #73485 [Com]: mail() adds a lone CR or LF

From: Date: Thu, 24 Nov 2016 05:55:13 +0000
Subject: Bug #73485 [Com]: mail() adds a lone CR or LF
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205593@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73485&edit=1 ID: 73485 Comment by: mattcoz at yahoo dot com Reported by: sherwoodsports at gmail dot com Summary: mail() adds a lone CR or LF Status: Not a bug Type: Bug Package: Mail related Operating System: All PHP Version: 7.0.X Block user comment: N Private report: N New Comment: I opened a new bug for my issue: https://bugs.php.net/bug.php?id=73507 Previous Comments: ------------------------------------------------------------------------ [2016-11-24 05:46:07] sherwoodsports at gmail dot com Hold up... the comments posted are not related to the original report. Please do not identify this bug with those comments then mark this bug as "not a bug" due to your analysis of the issue identified in the comments. ------------------------------------------------------------------------ [2016-11-24 03:03:50] yohgaki@php.net We have test cases for multiple headers by additional_headers parameter. http://lxr.php.net/xref/PHP-7.0/ext/standard/tests/mail/mail_basic6.phpt > mail("to@email.com", "Subject", "Message", "X-PHP-Fix: > x\r\nFrom: from@email.com"); This shouldn't produce following headers. > To: <to@email.com> > X-PHP-Originating-Script: 0:test.php > From: from@email.com > From: <from@email.com> I suppose this is your MTA issue. If you think this is a bug in PHP, try to add bug case to http://lxr.php.net/xref/PHP-7.0/ext/standard/tests/mail/mail_basic6.phpt You can run the test in PHP source build like TESTS=ext/standard/tests/mail/mail_basic6.phpt make test Attach modified mail_basic6.phpt file and reopen this bug. ------------------------------------------------------------------------ [2016-11-12 17:21:06] mattcoz at yahoo dot com I'm running Windows, so the MTA is not an issue. Also, I have no problem overriding the from address. I think I found where the problem might really be though. My server had the mail.add_x_header preference set to On for some reason. When I switch it to Off I no longer get the space before the rest of my headers. I'll open a new bug report for this specific issue and leave it Off on my server because I really don't need it. ------------------------------------------------------------------------ [2016-11-12 07:02:21] rasmus@php.net I don't think this is PHP doing this. At least not directly. Which MTA are you using? The first thing to understand here is that by default PHP just invokes an external MTA to send an email with the mail() function on non-Windows machines. The program that is run is defined by your sendmail_path ini setting. This also means we can override it to examine what exactly PHP is sending to the MTA program. Here is a test. Create this trivial PHP program: #!/usr/local/bin/php <?php file_put_contents("/tmp/test.log", file_get_contents("php://stdin"), FILE_APPEND); I called mine /home/rasmus/sm and I made it executable (chmod +x ./sm) Then I tried your example script of: <?php mail("to@email.com", "Subject", "Message", "From: from@email.com"); I ran it like this: php -d sendmail_path="/home/rasmus/sm" m The output I see in /tmp/test.log is: To: to@email.com Subject: Subject From: from@email.com Message What I think is happening here, at least for mattcoz at yahoo dot com is that the user invoking the MTA is not conifgured to be a trusted user and as such is not allowed to override the From address. The MTA inserts the space in front of it and adds its own From line. For sherwoodsports at gmail dot com, what is your mail() line that is producing that error? As you can see from my minimal test it doesn't appear that PHP is inserting an extra cr-lf in the headers. Again, it is likely some sort of interaction with your MTA. ------------------------------------------------------------------------ [2016-11-11 17:40:43] mattcoz at yahoo dot com I think this is the same as my issue. There seems to be an extra character before the additional headers. For example: mail("to@email.com", "Subject", "Message", "From: from@email.com"); To: <to@email.com> X-PHP-Originating-Script: 0:test.php From: from@email.com From: <from@email.com> An additional From header is added and this causes it to be blocked when sent to gmail addresses. On the other hand, if I put a dummy header before it: mail("to@email.com", "Subject", "Message", "X-PHP-Fix: x\r\nFrom: from@email.com"); To: <to@email.com> X-PHP-Originating-Script: 0:test.php X-PHP-Fix: x From: <from@email.com> This is sent successfully to gmail addresses. My guess is that this is the lone CR or LF that is causing his emails to fail. I have one server running 7.0.10 that is affected and one running 5.3.13 that is not affected, which matches his experience. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=73485 -- Edit this bug report at https://bugs.php.net/bug.php?id=73485&edit=1

« previous php.bugs (#205593) next »