PHPMailer\PHPMailer

PHPMailer::addAnAddressprotectedWP 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.

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

Хуков нет.

Возвращает

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

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->addAnAddress( $kind, $address, $name );
$kind(строка) (обязательный)
One of 'to', 'cc', 'bcc', or 'ReplyTo'.
$address(строка) (обязательный)
The email address to send, resp. to reply to.
$name(строка)
.
По умолчанию: ''

Код PHPMailer::addAnAddress() WP 6.9

protected function addAnAddress($kind, $address, $name = '')
{
    if (
        self::$validator === 'php' &&
        ((bool) preg_match('/[\x80-\xFF]/', $address))
    ) {
        //The caller has not altered the validator and is sending to an address
        //with UTF-8, so assume that they want UTF-8 support instead of failing
        $this->CharSet = self::CHARSET_UTF8;
        self::$validator = 'eai';
    }
    if (!in_array($kind, ['to', 'cc', 'bcc', 'Reply-To'])) {
        $error_message = sprintf(
            '%s: %s',
            self::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',
            self::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;
        }
    } else {
        foreach ($this->ReplyTo as $replyTo) {
            if (0 === strcasecmp($replyTo[0], $address)) {
                return false;
            }
        }
        $this->ReplyTo[] = [$address, $name];

        return true;
    }
    return false;
}