PHPMailer\PHPMailer

PHPMailer::addAnAddress()protectedWP 1.0

Add an address to one of the recipient arrays or to the ReplyTo array. Addresses that have been added already return false, but do not throw exceptions.

Method of the class: PHPMailer{}

No Hooks.

Return

true|false. true on success, false if address already used or invalid in some way

Usage

// protected - for code of main (parent) or child class
$result = $this->addAnAddress( $kind, $address, $name );
$kind(string) (required)
One of 'to', 'cc', 'bcc', or 'ReplyTo'
$address(string) (required)
The email address to send, resp. to reply to
$name(string)
-
Default: ''

PHPMailer::addAnAddress() code WP 6.5.2

protected function addAnAddress($kind, $address, $name = '')
{
    if (!in_array($kind, ['to', 'cc', 'bcc', 'Reply-To'])) {
        $error_message = sprintf(
            '%s: %s',
            $this->lang('Invalid recipient kind'),
            $kind
        );
        $this->setError($error_message);
        $this->edebug($error_message);
        if ($this->exceptions) {
            throw new Exception($error_message);
        }

        return false;
    }
    if (!static::validateAddress($address)) {
        $error_message = sprintf(
            '%s (%s): %s',
            $this->lang('invalid_address'),
            $kind,
            $address
        );
        $this->setError($error_message);
        $this->edebug($error_message);
        if ($this->exceptions) {
            throw new Exception($error_message);
        }

        return false;
    }
    if ('Reply-To' !== $kind) {
        if (!array_key_exists(strtolower($address), $this->all_recipients)) {
            $this->{$kind}[] = [$address, $name];
            $this->all_recipients[strtolower($address)] = true;

            return true;
        }
    } elseif (!array_key_exists(strtolower($address), $this->ReplyTo)) {
        $this->ReplyTo[strtolower($address)] = [$address, $name];

        return true;
    }

    return false;
}