Hello,
when I add 'Cc' header in code for mail, PHPMailer really sends an email with properly set 'CC' header. But problem appears when MimeMail is main MailSystem class, and using PHPMailer as engine. It never sends CC header.
Tracing back from MimeMail code, in mimemail.mail.inc, it implements MailSytemInterface and method mail, which finds mail engine (PHPMailer in this case) and tries to run phpmailer_mailengine (PHPMailer's hook_mailengine implementation). Parameters for that hook are $op (exactly: 'send') and $message (which as an array of headers and body). For operation 'send', it loads phpmailer.mimemail.inc, and passes there data array to function mimemail_phpmailer_send() in it. Everything there is so fine until line 60 (right after it adds CC and BCC to $mail object):
unset($message['headers']['Cc'], $message['headers']['Bcc']);
In the end, it runs method SmtpSend, which calls parent implementation (PHPMailer from library) and in the end finishes in SMTP class, method data. There it receives array of body and headers, explode them and prepare SMTP DATA to send. The issue seems to be that it is missing 'CC' header here, which was removed in quoted code above in phpmailer.mimemail.inc.
Since PHPMailer unset that header, this is an issue with PHPMailer, but only in its implementation part for MimeMail. Commenting that unset() line, makes Mimemail sending through PHPMailer email with properly set CC header.
Looking back in PHPMailer git log, that line was added in commit 4632251b6dc898182b6afd30387ddaba09f2fe1a 05/07/2009, but I am not sure why. Is there particular reason why do you unset CC and BCC headers explicitly before moving forward in sending email?
Thank you
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | phpmailer-keep-cc-header-3001310-2.patch | 1.25 KB | das-peter |
Comments
Comment #2
das-peter commentedJust stumbled over this too. I'd say this is simply a bug.
I've evaluated more of the code and it seems not only the mime mail integration but also the native handling is affected.
The mails will be send to all recipients as the SMTP protocol / phpmailer doesn't really care about these headers, however the metadata are lost.
This is fair for BCC - even a recommended approach: https://tools.ietf.org/html/rfc5322#section-3.6.3 - but CC should remain.
The error seems to origin in the original D7 port: #811774: Port to D7 (79d80fb3820d4c16d30ad43539c2f126660ca887) and the code was touched once after #927646: Bogus case of Cc and Bcc mail header fields
Attached patch only removes the Bcc header. The Cc Header now should show up in the Mail Client.
Comment #3
astonvictor commentedD7 reached its EOL back in January 2025, and there is no active release for D7 for this module anymore.
Development or support is not planned for D7. All D7-related issues are marked as outdated in a bunch.