When trying to send a message with Zend\Mail to multiple BCC or CC recipients, only the first recipient in the list will receive the email. Multiple normal recipients aren't a problem.
$mail = new Mail\Message();
$mail->setBcc([
'[email protected]',
'[email protected]',
'[email protected]',
]);
It doesn't make a difference to use setBcc or addBcc of the Message object.
The Issue
The problem belongs to a wrong format of the
Zend\Mailheader generation. It usesline-breaksbetween allCCorBCCrecipients. As fully described in this post, the workaround is to fix the folding.For example, this snippet:
Will create such header:
The problem, for at least some servers (like Micrsoft Exchange), is the line-breaks after the recipients. To fix this issue, the best way IMO would be an own Header class, because the line-breaks are hard-coded in Zend\Mail.
The Solution
Just copy
\Zend\Mail\Header\Bccclass to your module and overwrite thegetFieldValuefunction in there. With this approach you will be stay compatible on updates in the future.The recipients will now be passed by the new header class to the
Messageobject.That's it, the new header will be generated correctly:
For more details about the issue and the solution, take a look to the original post.