|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73507 Extra space added before additional headers when mail.add_x_header is enabled
Submitted: 2016-11-12 18:10 UTC Modified: 2016-11-24 20:53 UTC
From: mattcoz at yahoo dot com Assigned:
Status: Not a bug Package: *Mail Related
PHP Version: 7.0.13 OS: Windows
Private report: No CVE-ID: None
 [2016-11-12 18:10 UTC] mattcoz at yahoo dot com
When the server is set up with the mail.add_x_header preference enabled, an extra space is added before the additional headers. In my example where I set the From address in my additional headers, this causes it to add an additional From header. The email is then blocked if sent to gmail addresses. This does not happen on another server running PHP 5.3.13 with the same settings.

I've attempted to look at the mail.c code and find the problem, but I don't see anywhere that might explain why the extra space is being added.

Test script:
mail("", "Subject", "Message", "From:");

Expected result:
To: <>
X-PHP-Originating-Script: 0:test.php
From: <>

Actual result:
To: <>
X-PHP-Originating-Script: 0:test.php
From: <>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-13 15:06 UTC]
I can't reproduce the reported behavior (neither on Windows with
php-7.0.13-nts-Win32-VC14-x86, nor on Linux with current PHP-5.6
and PHP-7.0):

php -n -d mail.add_x_header=1 -d sendmail_path="cat -" -r "mail('', 'Subject', 'Message', 'From:');"
Subject: Subject
X-PHP-Originating-Script: 1:Command line code

 [2016-11-21 11:24 UTC]
-Status: Open +Status: Feedback
 [2016-11-21 11:24 UTC]
I don't reproduce this as well, debugged also through the Windows only sendmail part. @mattcoz at yahoo dot com, there must be something in the configuration, or the data, so we can reproduce this as well.

 [2016-11-21 16:52 UTC] mattcoz at yahoo dot com
-Status: Feedback +Status: Open
 [2016-11-21 16:52 UTC] mattcoz at yahoo dot com
Ok, so I tried this on another server with a fresh copy of PHP 7.0.13. I created a php.ini file with the only settings being my smtp server and mail.add_x_header = On. I then tested my script and got the same problem.
 [2016-11-21 18:50 UTC]
-Status: Open +Status: Feedback
 [2016-11-21 18:50 UTC]
@mattcoz at yahoo dot com, please describe in detail the way you trigger the bug.

 [2016-11-24 05:50 UTC] mattcoz at yahoo dot com
What additional detail are you looking for?
 [2016-11-24 17:15 UTC] mattcoz at yahoo dot com
Ok, I tested this with a different SMTP server and the problem goes away. I'm not sure why this would have been working in PHP5 though.
 [2016-11-24 20:53 UTC]
-Status: Feedback +Status: Not a bug
 [2016-11-24 20:53 UTC]
Some MTA/UMA treat LF, CR as CR/LF, convert LF, CR to CR/LF, but others not.
These things can happen.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 18:01:23 2020 UTC