PHPMailer\PHPMailer

PHPMailer::parseSimplerAddressesprotected staticWP 1.0

Parse a string containing one or more RFC822-style comma-separated email addresses with the form "display name <address>" into an array of name/address pairs. Uses a simpler parser that does not require the IMAP extension but doesnt support the full RFC822 spec. For full RFC822 support, use the PHP IMAP extension.

Method of the class: PHPMailer{}

No Hooks.

Returns

Array.

Usage

$result = PHPMailer::parseSimplerAddresses( $addrstr, $charset );
$addrstr(string) (required)
The address list string.
$charset(string) (required)
The charset to use when decoding the address list string.

PHPMailer::parseSimplerAddresses() code WP 7.0

protected static function parseSimplerAddresses($addrstr, $charset)
{
    // Emit a runtime notice to recommend using the IMAP extension for full RFC822 parsing
    trigger_error(self::lang('imap_recommended'), E_USER_NOTICE);

    $addresses = [];
    $list = explode(',', $addrstr);
    foreach ($list as $address) {
        $address = trim($address);
        //Is there a separate name part?
        if (strpos($address, '<') === false) {
            //No separate name, just use the whole thing
            if (static::validateAddress($address)) {
                $addresses[] = [
                    'name' => '',
                    'address' => $address,
                ];
            }
        } else {
            $parsed = static::parseEmailString($address);
            $email = $parsed['email'];
            if (static::validateAddress($email)) {
                $name = static::decodeHeader($parsed['name'], $charset);
                $addresses[] = [
                    //Remove any surrounding quotes and spaces from the name
                    'name' => trim($name, '\'" '),
                    'address' => $email,
                ];
            }
        }
    }

    return $addresses;
}