protected function PHPMailer::addOrEnqueueAnAddress
Search API
5.x PHPMailer.php | protected PHPMailer::addOrEnqueueAnAddress($kind, $address, $name) |
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.
Parameters
string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo':
string $address The email address to send, resp. to reply to:
string $name:
Return value
bool true on success, false if address already used or invalid in some way
Throws
4 calls to PHPMailer::addOrEnqueueAnAddress()
- PHPMailer::addAddress in inc/
PHPMailer/ src/ PHPMailer.php - Add a "To" address.
- PHPMailer::addBCC in inc/
PHPMailer/ src/ PHPMailer.php - Add a "BCC" address.
- PHPMailer::addCC in inc/
PHPMailer/ src/ PHPMailer.php - Add a "CC" address.
- PHPMailer::addReplyTo in inc/
PHPMailer/ src/ PHPMailer.php - Add a "Reply-To" address.
File
- inc/
PHPMailer/ src/ PHPMailer.php, line 1011
Class
- PHPMailer
- PHPMailer - PHP email creation and transport class.
Namespace
PHPMailer\PHPMailerCode
protected function addOrEnqueueAnAddress($kind, $address, $name)
{
$address = trim($address);
$name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
$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;
}
$params = [$kind, $address, $name];
// Enqueue addresses with IDN until we know the PHPMailer::$CharSet.
if ($this->has8bitChars(substr($address, ++$pos)) and static::idnSupported()) {
if ('Reply-To' != $kind) {
if (!array_key_exists($address, $this->RecipientsQueue)) {
$this->RecipientsQueue [$address] = $params;
return true;
}
}
else {
if (!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);
}