You are here

private function PHPMailer::AddAnAddress in SMTP Authentication Support 7

Same name and namespace in other branches
  1. 7.2 smtp.phpmailer.inc \PHPMailer::AddAnAddress()

Adds an address to one of the recipient arrays Addresses that have been added already return FALSE, but do not throw exceptions

@access private

Parameters

string $kind One of 'to', 'cc', 'bcc', 'ReplyTo':

string $address The email address to send to:

string $name:

Return value

boolean TRUE on success, FALSE if address already used or invalid in some way

5 calls to PHPMailer::AddAnAddress()
PHPMailer::AddAddress in ./smtp.phpmailer.inc
Adds a "To" address.
PHPMailer::AddBCC in ./smtp.phpmailer.inc
Adds a "Bcc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
PHPMailer::AddCC in ./smtp.phpmailer.inc
Adds a "Cc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
PHPMailer::AddReplyTo in ./smtp.phpmailer.inc
Adds a "Reply-to" address.
PHPMailer::SetFrom in ./smtp.phpmailer.inc
Set the From and FromName properties

File

./smtp.phpmailer.inc, line 464
The mail handler class in smtp module, based on code of the phpmailer library, customized and relicensed to GPLv2.

Class

PHPMailer
PHPMailer - PHP email transport class NOTE: Requires PHP version 5 or later @package PHPMailer @author Andy Prevost @author Marcus Bointon @copyright 2004 - 2009 Andy Prevost

Code

private function AddAnAddress($kind, $address, $name = '') {
  if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
    if ($this->logging) {
      watchdog('smtp', 'Invalid recipient array: %kind', array(
        '%kind' => $kind,
      ), WATCHDOG_ERROR);
    }
    return FALSE;
  }
  $address = trim($address);
  $name = trim(preg_replace('/[\\r\\n]+/', '', $name));

  //Strip breaks and trim
  if (!self::ValidateAddress($address)) {
    $this
      ->SetError(t('Invalid address') . ': ' . $address);
    if ($this->exceptions) {
      throw new phpmailerException(t('Invalid address') . ': ' . $address);
    }
    if ($this->logging) {
      watchdog('smtp', 'Invalid address: %address', array(
        '%address' => $address,
      ), WATCHDOG_ERROR);
    }
    return FALSE;
  }
  if ($kind != 'ReplyTo') {
    if (!isset($this->all_recipients[strtolower($address)])) {
      array_push($this->{$kind}, array(
        $address,
        $name,
      ));
      $this->all_recipients[strtolower($address)] = TRUE;
      return TRUE;
    }
  }
  else {
    if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
      $this->ReplyTo[strtolower($address)] = array(
        $address,
        $name,
      );
      return TRUE;
    }
  }
  return FALSE;
}