Make WordPress Core

Opened 7 years ago

Closed 10 days ago

Last modified 6 days ago

#43425 closed defect (bug) (worksforme)

WP_Mail BCC and CC - RCPT TO Errors

Reported by: jwgarber1725's profile JWGarber1725 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9.4
Component: Mail 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.

Change History (2)

#1 @SirLouen
10 days ago

  • Resolution set to worksforme
  • Status changed from new to closed

Reproduction Report

Description

❌ This report can't validate that the issue can be reproduced.

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.28
  • Server: nginx/1.29.0
  • Database: mysqli (Server: 8.4.5 / Client: mysqlnd 8.2.28)
  • Browser: Chrome 138.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-Five 1.2
  • MU Plugins: None activated
  • Plugins:
    • Micro Email Testing 1.0.0
    • Testing Emails 1.0.0
    • Test Reports 1.2.0

Testing instructions

  1. Used the code provided by OP for email testing.

Actual Results

  1. ❌ Error condition is not occurring any more

Additional Notes

  • First, you must consider, that WordPress use PHPMailer, not mail function directly. Although the function looks very similar, ideally you should respect the PHPMailer principles

For the first code, I tried, and I received the CC in the source

Cc: myotheremail@myname.com
Content-Type: text/plain; charset=UTF-8
Date: Thu, 10 Jul 2025 07:56:31 +0000
From: Test <wordpress@mailhog.local>
MIME-Version: 1.0
Message-ID: <d2jCdMLdqbdAmfggEcNWXMVc9fMIdkFn72uaaWTE4@localhost.localdomain>
Received: from localhost.localdomain by mailhog.example (MailHog)
          id 0i0vUZJ4L-HDW2m_7Kiv_U2FitXfsO6tnkrFMtqP6XI=@mailhog.example; Thu, 10 Jul 2025 07:56:31 +0000
Return-Path: <wordpress@mailhog.local>
Subject: TEST SUBJECT
To: myemail@gmail.com
X-Mailer: PHPMailer 6.9.3 (https://github.com/PHPMailer/PHPMailer)

Test

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:

$headers = 'From: Test <help@myname.com>' . "\r\n" . 'cc: myotheremail@myname.com' . "\r\n" . 'bcc: myotherotheremail@myname.com';
$to = "myemail@gmail.com";
$subject = "TEST BCC PART 2";
$body = "Test";

This are the logs:

"Raw": {
    "From": "wordpress@mailhog.local",
    "To": [
      "myemail@gmail.com",
      "myotheremail@myname.com",
      "myotherotheremail@myname.com"
    ],
    "Data": "Date: Thu, 10 Jul 2025 09:38:26 +0000\r\nTo: myemail@gmail.com\r\nFrom: Test \u003cwordpress@mailhog.local\u003e\r\nCc: myotheremail@myname.com\r\nSubject: TEST BCC PART 2\r\nMessage-ID: \u003cESYCWyPLK2jSL3xWLCoFkuFVFTYnXrm0XKT4RAjw@localhost.localdomain\u003e\r\nX-Mailer: PHPMailer 6.9.3 (https://github.com/PHPMailer/PHPMailer)\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\n\r\nTest\r\n",
    "Helo": "localhost.localdomain"
  }

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:

$headers = array(
	'From: Test <help@myname.com>',
	'Bcc: myotheremail@myname.com',
);

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 to PHPMailer completely bypassing wp_mail with this hook. Then you can use PHPMailer class methods like addCC and addBCC

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.

Bcc: myotherotheremail@myname.com
Return-Path: <test@example.com>
Received: from localhost (unknown [172.18.0.1])
        by 185d76cd24e6 (Mailpit) with SMTP
        for <myemail@gmail.com>; Thu, 10 Jul 2025 11:43:08 +0000 (UTC)
Date: Thu, 10 Jul 2025 11:43:08 +0000
To: myemail@gmail.com
From: Test <test@example.com>
Cc: myotheremail@myname.com
Reply-To: help@myname.com
Subject: TEST BCC PART 2
Message-ID: <jGQkaTld1vnJK6xluPctCy2gOU64ImAoWtzAvjh7Pw@localhost>
X-Mailer: WPMailSMTP/Mailer/smtp 4.5.0
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Last edited 10 days ago by SirLouen (previous) (diff)

#2 @peterwilsoncc
6 days ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.