#43425 closed defect (bug) (worksforme)
WP_Mail BCC and CC - RCPT TO Errors
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.9.4 |
Component: | Keywords: | ||
Focuses: | Cc: |
Description
Adding BCC and CC Fields are having inconsistent results. Undeliverable emails, incorrect "RCPT TO" Addresses in SMTP Communication etc. "RCPT TO" is being set to "Message-ID".
See Tests Below - I tested with standard PHP Mail and wp_mail
If anyone has any pointers that would be great.
Windows Server 2012R2
IIS: 8.5
PHP: 7.0.9
WP: 4.9.4
No special plugins or code.
Test 1: Standard PHP Mail with CC Field
$headers = 'From: Test <help@myname.com>' . "\r\n" . 'cc: myotheremail@myname.com'; $to = "myemail@gmail.com"; $subject = "TEST SUBJECT"; $body = "Test"; if (mail($to, $subject, $body, $headers)) { echo("Message successfully sent"); } else { echo("Message sending failed"); }
Results
Both emails received. Content looks ok
Test 2: Standard PHP Mail with BCC Field
$headers = 'From: Test <help@myname.com>' . "\r\n" . 'bcc: myotheremail@myname.com'; $to = "myemail@gmail.com"; $subject = "TEST SUBJECT"; $body = "Test"; if (mail($to, $subject, $body, $headers)) { echo("Message successfully sent"); } else { echo("Message sending failed"); }
Results: Both emails were received
However. The body of each email now has the letter "b" appended to the content.
Body Content
b Test
Is something in WP causing this or is this an issue in Windows PHP??
Test 3: WordPress wp_mail with CC Field
$headers = 'From: Test <help@myname.com>' . "\r\n" . 'cc: myotheremail@myname.com'; $to = "myemail@gmail.com"; $subject = "TEST SUBJECT"; $body = "Test"; if (wp_mail($to, $subject, $body, $headers)) { echo("Message successfully sent"); } else { echo("Message sending failed"); }
Results
CC never received - SMTP Log file shows: [2018.02.26] 16:46:04 [55583] CMD: RCPT TO:<945dc26bed6e74aeec984fc4ae828e32@…>
Why did the CC field get changed? It looks like the "CC" Field is now the "Message-ID" as they are the same now.
Gmail received the copy as expected.
Test 4: WordPress wp_mail with BCC Field
$headers = 'From: Test <help@myname.com>' . "\r\n" . 'bcc: myotheremail@myname.com'; $to = "myemail@gmail.com"; $subject = "TEST SUBJECT"; $body = "Test"; if (wp_mail($to, $subject, $body, $headers)) { echo("Message successfully sent"); } else { echo("Message sending failed"); }
Results
Same as Test 3 -- The BCC Field "RCPT TO" command became the "Message-ID"??
Gmail received the copy but still had the letter "b" appended into the message body.
Any ideas, pointers etc? Suspecting Bug in WordPress or Windows PHP.
Reproduction Report
Description
❌ This report can't validate that the issue can be reproduced.
Environment
Testing instructions
Actual Results
Additional Notes
For the first code, I tried, and I received the CC in the source
For the BCC part is a little more tricky because I'm using Mailhog for testing, which doesn't have support for handling clearly BCC deliveries other than the logs. I've tried not only adding BCC but CC also:
This are the logs:
So I don't see any problems with neither BCC or CC. Maybe there was a problem with your email delivery service OR it has been solved in certain PHPMailer vs over the years (given that this was reported 7 years ago).
Anyway, personally I recommend to configure the headers in a string array, like this:
Both methods work, for PHPMailer, this is slightly more robust.
Also if you are confident that there is a problem with
wp_mail
you can hook directly toPHPMailer
completely bypassingwp_mail
with this hook. Then you can usePHPMailer
class methods likeaddCC
andaddBCC
Closing this ticket as
worksforme
Extra Information
I switched to Mailpit for further testing and now I can better see BCC there, which happens to confirm the previous information.