php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71726 Headers are transformed wrongly
Submitted: 2016-03-07 09:39 UTC Modified: 2017-05-08 20:00 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: bugs dot php at myrosoft dot com Assigned: requinix (profile)
Status: Closed Package: Mail related
PHP Version: 7.0.4 OS: Windows 7
Private report: No CVE-ID: None
 [2016-03-07 09:39 UTC] bugs dot php at myrosoft dot com
Description:
------------
Sending mail under Windows can sometimes modify the headers wrongly. Different headers are mixed up.

eg.:
'Bcc: report.web@myrosoft.com'.$nl.
'Reply-to: noreply@myrosoft.com'.$nl.

maybe transformed to 
BReply-to: noreply@myrosoft.com

I have noticed different behaviour, depending on the script.


Test script:
---------------
http://myrosoft.com/Files/PhpBug/mail2.php


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-07 10:09 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2016-03-07 10:09 UTC] requinix@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

Also, what MTA are you using?
 [2016-03-20 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2017-04-28 12:35 UTC] jonathan dot tyler at loadaccess dot net
Hello,

I am running 7.1 (tested with x86 and x86_64) on IIS 8 - Windows Server 2012 R2.

I am seeing the same issue using PHPMailer in Joomla.

Though it's not shown below, there is always a BCC added (to webdev team) on mail sent from our site.

When I look at the mail headers after receiving it in my mailbox I see the following (personal details changed):

---
Subject: MyEmailSubject
To: My Name <me@mydomain.com>
X-PHP-Originating-Script: 0:class.phpmailer.php
Date: Fri, 28 Apr 2017 08:04:30 -0400
From: Website <mailer@mydomain.com>
BReply-To: Other Name <other-person@mydomain.com>
Message-ID: <fb6c4df7ce01bb2cc4a69e389fd971d2@www.mydomain.com>
X-Mailer: PHPMailer 5.2.16 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
---

If I switch back to 5.6.22:

---
Subject: MyEmailSubject
To: My Name <me@mydomain.com>
X-PHP-Originating-Script: 0:class.phpmailer.php
Date: Fri, 28 Apr 2017 08:14:44 -0400
From: Website <mailer@mydomain.com>
Reply-To: Other Name <other-person@mydomain.com>
Message-ID: <1ff963ff75dd75a170c47189df4c5e4a@www.tasktracker.ca>
X-Mailer: PHPMailer 5.2.16 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
---

Here's a sample email setup:

---
$mailer = JFactory::getMailer();
$mailer->LE = "\r\n"; // Line End CRLF
$mailer->isHTML(true);
$mailer->addRecipient('me@mydomain.com', 'My Name');
$mailer->addReplyTo('other-person@mydomain.com', 'Other Name');
$mailer->addBCC('dev@mydomain.com', 'Dev Team');
$mailer->setFrom('mailer@mydomain.com', 'Website');
$mailer->setSubject('MyEmailSubject');
$mailer->setBody( 'Testing ReplyTo issue.' );
$mailer->send();
---
 [2017-04-28 12:42 UTC] requinix@php.net
Same question for you: what MTA are you using?
 [2017-04-28 12:51 UTC] jonathan dot tyler at loadaccess dot net
Zimbra 8.7.1
 [2017-04-28 17:13 UTC] requinix@php.net
-Status: No Feedback +Status: Feedback
 [2017-04-28 17:13 UTC] requinix@php.net
I can reproduce the *results* easily enough, using something like
  BBcc: user@example.com
which I've made bug #74510 for, but I can't reproduce yet with code that isn't clearly wrong.

@jonathan, can you come up with a small-ish unredacted script (with or without using JMail+PHPMailer) that mirrors your code and gives the BReply-To outcome? You can use something like smtp4dev or Papercut to set up a local test SMTP server that logs messages instead of sending them, which would allow you to use fake data for everything. Additionally, testing your current code with smtp4dev/Papercut could at least help establish whether the problem is with PHP.

Meanwhile I'm still looking...
 [2017-04-28 17:45 UTC] jonathan dot tyler at loadaccess dot net
Thanks for the detailed next steps :)
I'll try and get some testing done using those methods over the weekend.
 [2017-05-07 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2017-05-08 15:23 UTC] jonathan dot tyler at loadaccess dot net
Sorry this took so long to get back to, but the issue has not been resolved....

Example mailer code:
----------
/*
 * Use PHPMailer with php.ini "mail function" settings. 
 * I'm sure just using the standard PHPMailer class without Joomla will produce the same.
 */
$mailer = JFactory::getMailer(); 
$mailer->LE = "\r\n"; // Line End CRLF
$mailer->isHTML(true);
$mailer->setFrom('mailer@example.com','SystemMailer');
$mailer->addRecipient('test@example.com','To Account');
$mailer->addCC('test2@example.com','CC Account');
$mailer->addBCC('test3@example.com','BCC Account');
$mailer->addReplyTo('test4@example.com','ReplyTo Account');
$mailer->setSubject('PHP 7.1.1 email Test');
$mailer->setBody('Sample email test.');

try
{   
    $mailer->send();            
}
catch (phpmailerException $e)
{        
    echo $e->errorMessage();
}
catch (Exception $e)
{        
    echo $e->getMessage();
}
----------

Output from Smtp4Dev (with BCC):
----------
Subject: PHP 7.1.1 email Test
To: To Account <test@example.com>
X-PHP-Originating-Script: 0:class.phpmailer.php
Date: Mon, 8 May 2017 11:14:53 -0400
From: SystemMailer <mailer@example.com>
Cc: CC Account <test2@example.com>
BReply-To: ReplyTo Account <test4@example.com>
Message-ID: <e426383c205069ba6724f3ee692142fb@localhost>
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8

Sample email test.
----------

Output from Smtp4Dev (without BCC):
----------
Subject: PHP 7.1.1 email Test
To: To Account <test@example.com>
X-PHP-Originating-Script: 0:class.phpmailer.php
Date: Mon, 8 May 2017 11:18:54 -0400
From: SystemMailer <mailer@example.com>
Cc: CC Account <test2@example.com>
Reply-To: ReplyTo Account <test4@example.com>
Message-ID: <820a74989fdb906369fd2be445a0d06c@localhost>
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8

Sample email test.
----------

Switching around the order of the PHPMailer functions doesn't have an effect.

If I remove BCC I get the replyTo correctly, but I can't tell what happens with the BCC if I remove the replyTo as it's not shown in smtp4dev.
 [2017-05-08 16:49 UTC] jonathan dot tyler at loadaccess dot net
Also, I should add, the To: column in smtp4dev shows the following:

With BCC - To: test@example.com, test2@example.com, test3@example.com
Without BCC - To: test@example.com, test2@example.com

So it does appear to be picking up the BCC email address, but it's messing up the ReplyTo in the process.
 [2017-05-08 17:42 UTC] requinix@php.net
-Status: No Feedback +Status: Feedback
 [2017-05-08 17:42 UTC] requinix@php.net
I still haven't been able to reproduce either. Using PHPMailer 5.2.23.

Let's try PHPMailer without mail(). Can you do the same email but using
  $mailer->isSMTP();
  $mailer->Host = "localhost";
  $mailer->Port = 25;
  $mailer->SMTPDebug = 3;

Assuming that works correctly, try the reverse of mail() without PHPMailer:

$headers = implode("\r\n", [
  "From: SystemMailer <mailer@example.com>",
  "Cc: CC Account <test2@example.com>",
  "X-Foo: foo",
  "Bcc: BCC Account <test3@example.com>",
  "X-Bar: bar",
  "Reply-To: ReplyTo Account <test4@example.com>"
]);
mail("test@example.com", "PHP 7.1.1 email Test", "Sample email test.", $headers);
 [2017-05-08 18:37 UTC] jonathan dot tyler at loadaccess dot net
When using the isSMTP() flag I had to use our internal mail server, smtp4dev keeps crashing with some SSL socket connection error.
That said, it worked and the headers showed the correct ReplyTo.
I setup myself as the BCC and received the email.

-----------
Date: Mon, 8 May 2017 14:33:20 -0400
To: To Account <test@example.com>
From: Jonathan Tyler <jonathan.tyler@loadaccess.net>
Cc: CC Account <test2@example.com>
Reply-To: ReplyTo Account <no-reply@loadaccess.net>
Subject: PHP 7.1.1 email Test
Message-ID: <a7f4ba9cb99fd0981f0301f4167e6cbb@localhost>
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8

Sample email test.
-------------

For your second suggested test (I switched back to localhost):

Date: Mon, 08 May 2017 14:21:09 -0400
Subject: PHP 7.1.1 email Test
To: test@example.com
X-PHP-Originating-Script: 0:mailtest.php
From: SystemMailer <mailer@example.com>
Cc: CC Account <test2@example.com>
X-Foo: foo
BX-Bar: bar
Reply-To: ReplyTo Account <test4@example.com>

Sample email test.
-----------------

It doesn't appear to have worked, as noted by the BX-Bar.
 [2017-05-08 18:41 UTC] jonathan dot tyler at loadaccess dot net
I just realized I should include my laptop system setup.

Windows 10 Pro
IIS Express
PHP 7.1.1 (x86_64)

Joomla 3.7.0
PHPMailer 5.2.22

I'll look and see if there's a new version of PHPMailer. Looks like I may have to manually update Joomla.
 [2017-05-08 19:42 UTC] requinix@php.net
Reproduced! Script is that implode+mail stuff from earlier and it only happens with php-cgi.exe.
However it seems to be fixed already in 7.0.18 and 7.1.4. Can you confirm that?
 [2017-05-08 19:57 UTC] jonathan dot tyler at loadaccess dot net
That worked!
I downloaded 7.1.4 and overwrote the 7.1.1 files that IIS (Web Platform) installed (7.1.4 is not available through Web Platform Installer yet apparently).

Subject: PHP 7.1.4 email Test
To: To Name <test@example.com>
X-PHP-Originating-Script: 0:class.phpmailer.php
Date: Mon, 8 May 2017 15:55:22 -0400
From: From Name <me@example.com>
Cc: CC Name <test2@example.com>
Reply-To: ReplyTo Name <no-reply@example>
Message-ID: <ae34994b9985737c93c1533a28620558@localhost>
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8

Sample email test.

Thanks for helping narrow down the culprit ;) I just have to do the same thing I our Servers now.
 [2017-05-08 20:00 UTC] requinix@php.net
-Status: Feedback +Status: Closed -Assigned To: +Assigned To: requinix
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Wed Oct 17 23:01:26 2018 UTC