Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Email delivery

PHPMailer addCC() adds no CC recipient

ErroraddCC() returns false

Short answer

addCC() returns false when it rejects the address, and PHPMailer then sends without that CC. The documented reasons are an address that is invalid, such as the Name <address> form, or one already used on the message. In a loop, clear recipients after each send. Always check the return value.

  • Applies to PHP 8.3, PHPMailer 6, PHPMailer 7
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print what addCC() returns and turn on server debugging. A false means PHPMailer refused the address before anything was sent.

    <?php
    use PHPMailer\PHPMailer\SMTP;
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;
    var_dump($mail->addCC('cc@example.com'));
    echo $mail->ErrorInfo;
  2. 2Match what you see, then jump to its fix

    1. 1addCC() returns false for a value like Joe User <joe@example.com>The address is not a bare addressFix
    2. 2addCC() returns false for an address that looks validThe address is already on the messageFix
    3. 3In a loop, a CC address gets a message meant for someone else, or a new CC is refused as already usedRecipients from the previous message are still on the objectFix

What does the error look like?

  • addCC() returns false
  • The mail arrives for the To address but not for the CC address
  • The CC address receives a message meant for a previous recipient

Cause 1 of 3

The address is not a bare address

1Check

The PHPMailer troubleshooting guide says addresses must be bare. The display-name format is not accepted in the address argument; the name goes in the second argument.

<?php
var_dump($mail->addCC('Joe User <joe@example.com>'));
var_dump($mail->addCC('joe@example.com', 'Joe User'));

2Fix

Split the value into an address and a name before calling addCC().

<?php
$mail->addCC('joe@example.com', 'Joe User');

3Verify

Both the return value and the list of CC addresses show the recipient.

<?php
var_dump($mail->getCcAddresses());

Confirmed by github.com

Did this fix it?

Cause 2 of 3

The address is already on the message

1Check

The reference says addCC() returns false if the address was already used or is invalid in some way. Adding the same person to To and CC, or calling addCC() twice with one address, triggers it.

<?php
var_dump($mail->getCcAddresses());

2Fix

Add each address to one list only. If the same value comes from a form field, remove duplicates first and keep the address in To or in CC, not both.

<?php
$to = 'a@example.com';
$cc = 'a@example.com';
$mail->addAddress($to);
if ($cc !== $to) {
    $mail->addCC($cc);
}

3Verify

Every addCC() call you expect to work returns true.

<?php
var_dump($mail->addCC('b@example.com'));

Confirmed by phpmailer.github.io

Did this fix it?

Cause 3 of 3

Recipients from the previous message are still on the object

1Check

One PHPMailer object keeps its recipients until you clear them. The sending-to-lists guide says to clear addresses after each send inside a loop, and the class has clearCCs() and clearAllRecipients() for CC and for every recipient type.

<?php
var_dump($mail->getCcAddresses());

2Fix

Clear the recipients after every send, or create a fresh PHPMailer object per message.

<?php
foreach ($messages as $m) {
    $mail->addAddress($m['to']);
    $mail->addCC($m['cc']);
    $mail->send();
    $mail->clearAllRecipients();
}

3Verify

Before each iteration getCcAddresses() is empty, and each CC receives only its own message.

<?php
var_dump($mail->getCcAddresses());

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Treat the boolean from addAddress(), addCC() and addBCC() as part of the call: log or stop when it is false.
  • Use bare addresses and pass the display name as the second argument.
  • Keep recipient lists per message, and clear them before the next message.
  • Keep SMTPDebug at DEBUG_SERVER while testing so the server conversation is visible.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.