PHPMailer\PHPMailer

PHPMailer::addOrEnqueueAnAddress()protectedWP 1.0

Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still be modified after calling this function), addition of such addresses is delayed until send(). Addresses that have been added already return false, but do not throw exceptions.

Метод класса: PHPMailer{}

Хуков нет.

Возвращает

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

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->addOrEnqueueAnAddress( $kind, $address, $name );
$kind(строка) (обязательный)
One of 'to', 'cc', 'bcc', or 'ReplyTo'
$address(строка) (обязательный)
The email address
$name(строка) (обязательный)
An optional username associated with the address

Код PHPMailer::addOrEnqueueAnAddress() WP 6.1.1

protected function addOrEnqueueAnAddress($kind, $address, $name)
{
    $pos = false;
    if ($address !== null) {
        $address = trim($address);
        $pos = strrpos($address, '@');
    }
    if (false === $pos) {
        //At-sign is missing.
        $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 ($name !== null && is_string($name)) {
        $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
    } else {
        $name = '';
    }
    $params = [$kind, $address, $name];
    //Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
    //Domain is assumed to be whatever is after the last @ symbol in the address
    if (static::idnSupported() && $this->has8bitChars(substr($address, ++$pos))) {
        if ('Reply-To' !== $kind) {
            if (!array_key_exists($address, $this->RecipientsQueue)) {
                $this->RecipientsQueue[$address] = $params;

                return true;
            }
        } elseif (!array_key_exists($address, $this->ReplyToQueue)) {
            $this->ReplyToQueue[$address] = $params;

            return true;
        }

        return false;
    }

    //Immediately add standard addresses without IDN.
    return call_user_func_array([$this, 'addAnAddress'], $params);
}