PHPMailer\PHPMailer

PHPMailer::parseAddressespublic staticWP 1.0

Parse and validate a string containing one or more RFC822-style comma-separated email addresses of the form "display name <address>" into an array of name/address pairs. Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. Note that quotes in the name part are removed.

Method of the class: PHPMailer{}

No Hooks.

Returns

Array.

Usage

$result = PHPMailer::parseAddresses( $addrstr, $useimap, $charset );
$addrstr(string) (required)
The address list string.
$useimap(null)
Deprecated argument since 6.11.0.
Default: null
$charset(string)
The charset to use when decoding the address list string.
Default: self::CHARSET_ISO88591

Notes

PHPMailer::parseAddresses() code WP 6.9.1

public static function parseAddresses($addrstr, $useimap = null, $charset = self::CHARSET_ISO88591)
{
    if ($useimap !== null) {
        trigger_error(self::lang('deprecated_argument'), E_USER_DEPRECATED);
    }
    $addresses = [];
    if (function_exists('imap_rfc822_parse_adrlist')) {
        //Use this built-in parser if it's available
        $list = imap_rfc822_parse_adrlist($addrstr, '');
        // Clear any potential IMAP errors to get rid of notices being thrown at end of script.
        imap_errors();
        foreach ($list as $address) {
            if (
                '.SYNTAX-ERROR.' !== $address->host &&
                static::validateAddress($address->mailbox . '@' . $address->host)
            ) {
                //Decode the name part if it's present and maybe encoded
                if (
                    property_exists($address, 'personal')
                    && is_string($address->personal)
                    && $address->personal !== ''
                ) {
                    $address->personal = static::decodeHeader($address->personal, $charset);
                }

                $addresses[] = [
                    'name' => (property_exists($address, 'personal') ? $address->personal : ''),
                    'address' => $address->mailbox . '@' . $address->host,
                ];
            }
        }
    } else {
        //Use this simpler parser
        $addresses = static::parseSimplerAddresses($addrstr, $charset);
    }

    return $addresses;
}