Search code examples
phpphpmailer

PHPMailer - how to check if address(es) added


You add addresses via $mailer->addAddress($address['mail'], $address['name']);. But how do you check if there are any address(es) added to the PHPMailer instance?

Pseudo code:

if (count($mailer->Addresses) > 0) {
    $mailer->send();
}

Thanks in advance!


Solution

  • You can use getAllRecipientAddresses() function
    of PHPMailer class to get all the email addresses.

    https://github.com/PHPMailer/PHPMailer/blob/master/src/PHPMailer.php#L4988

    It allows for public read access to all_recipients property.