You are here

function phpmailer_parse_address in PHPMailer 6

Same name and namespace in other branches
  1. 8.3 phpmailer.module \phpmailer_parse_address()
  2. 5.2 phpmailer.module \phpmailer_parse_address()
  3. 5 phpmailer.module \phpmailer_parse_address()
  4. 6.3 phpmailer.module \phpmailer_parse_address()
  5. 6.2 phpmailer.module \phpmailer_parse_address()
  6. 7.4 phpmailer.module \phpmailer_parse_address()
  7. 7.3 phpmailer.module \phpmailer_parse_address()

Extract address and optional display name of an e-mail address.

Parameters

$address: A string containing one or more valid e-mail address(es) separated with commas.

Return value

An array containing all found e-mail addresses split into mail and name.

See also

http://tools.ietf.org/html/rfc5322#section-3.4

2 calls to phpmailer_parse_address()
mimemail_phpmailer_send in includes/mimemail.inc
Send out an e-mail.
phpmailer_send in includes/phpmailer.inc
Send out an e-mail.

File

./phpmailer.module, line 96
This module integrates PHPMailer with Drupal, both as native drupal_mail() wrapper, and as part of the Mime Mail module.

Code

function phpmailer_parse_address($address) {
  $parsed = array();
  $regexp = "/^(.*) <([a-z0-9]+(?:[_\\.-][a-z0-9]+)*@(?:[a-z0-9]+(?:[\\.-][a-z0-9]+)*)+\\.[a-z]{2,})>\$/i";

  // Split multiple addresses and process each.
  foreach (explode(',', $address) as $email) {
    $email = trim($email);
    if (preg_match($regexp, $email, $matches)) {
      $parsed[] = array(
        'mail' => $matches[2],
        'name' => trim($matches[1], '"'),
      );
    }
    else {
      $parsed[] = array(
        'mail' => $email,
        'name' => '',
      );
    }
  }
  return $parsed;
}