Subject header is duplicated
Summary On Windows with PHP 7, when sending an mail message with the Sendmail transport, the subject header is duplicated.
Steps to reproduce To reproduce the bug the sample from here can be used: http://framework.zend.com/manual/current/en/modules/zend.mail.introduction.html
The resulting mail headers look something like this: Subject: Test Subject Date: Wed, 29 Jul 2015 17:33:17 +0000 From: =?UTF-8?Q?test?= [email protected] To: [email protected] Subject: Test Subject
Cause In the Sendmail transport all headers (including the Subject) and the subject itself are passed to the php mail function: $result = mail($to, $subject, $message, $headers); The mail function then appends to the $subject to the $headers. I do not think the php mail function should handle this case because it doesn't know what subject the caller intended to use. However I believe php mail should at least issue a warning (TBD: file enhancement at https://bugs.php.net/).
Solution Pass the headers without the Subject header to the php mail function. This is already done if the os is not Windows in the prepareHeaders. I think it should be done for Windows as well.
I was not able to reproduce this error. It seems, it is fixed in the current version.
Successfully tested on Windows 10 Pro with php-7.1.26-Win32-VC14-x64, php-7.2.15-Win32-VC15-x64 and php-7.3.2-Win32-VC15-x64.
Used quickstart example for Sendmail Transport Usage
use Zend\Mail\Message;
use Zend\Mail\Transport\Sendmail as SendmailTransport;
$message = new Message();
$message->addTo('[email protected]');
$message->addFrom('[email protected]');
$message->setSubject('Greetings and Salutations!');
$message->setBody("Sorry, I'm going to be late today!");
$transport = new SendmailTransport();
$transport->send($message);
Received mail
Date: Tue, 05 Mar 2019 08:50:08 +0100
From: [email protected]
To: [email protected], [email protected]
Subject: Greetings and Salutations!, Greetings and Salutations!
Sorry, I'm going to be late today!
Edit: zend-mail v2.10.0
But why is To duplicated in your test result?
And for clarity include the value of your current zend-mail version.
Very good observation, I will have a look into it. This might be a new issue.
This repository has been closed and moved to laminas/laminas-mail; a new issue has been opened at https://github.com/laminas/laminas-mail/issues/72.