protected \Joomla\CMS\Mail\Mail|bool
add
(mixed $recipient, mixed $name = '', mixed $method = 'addAddress')
/**
* Add recipients to the email.
*
* @param mixed $recipient Either a string or array of strings [email address(es)]
* @param mixed $name Either a string or array of strings [name(s)]
* @param string $method The parent method's name.
*
* @return Mail|boolean Returns this object for chaining on success or boolean false on failure.
*
* @since 1.7.0
*
* @throws \InvalidArgumentException if the argument array counts do not match
* @throws phpmailerException if setting the address failed and exception throwing is enabled
*/
protected function add($recipient, $name = '', $method = 'addAddress')
{
$method = lcfirst($method);
// If the recipient is an array, add each recipient... otherwise just add the one
if (\is_array($recipient)) {
if (\is_array($name)) {
$combined = array_combine($recipient, $name);
if ($combined === false) {
throw new \InvalidArgumentException("The number of elements for each array isn't equal.");
}
foreach ($combined as $recipientEmail => $recipientName) {
$recipientEmail = MailHelper::cleanLine($recipientEmail);
$recipientName = MailHelper::cleanLine($recipientName);
// Check for boolean false return if exception handling is disabled
if (\call_user_func('parent::' . $method, $recipientEmail, $recipientName) === false) {
return false;
}
}
} else {
$name = MailHelper::cleanLine($name);
foreach ($recipient as $to) {
$to = MailHelper::cleanLine($to);
// Check for boolean false return if exception handling is disabled
if (\call_user_func('parent::' . $method, $to, $name) === false) {
return false;
}
}
}
} else {
$recipient = MailHelper::cleanLine($recipient);
// Check for boolean false return if exception handling is disabled
if (\call_user_func('parent::' . $method, $recipient, $name) === false) {
return false;
}
}
return $this;
}