PHPMailer\PHPMailer
PHPMailer::parseAddresses
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 and the deprecated $useimap argument is truthy. Note that quotes in the name part are removed.
Метод класса: PHPMailer{}
Хуков нет.
Возвращает
array.
Использование
$result = PHPMailer::parseAddresses( $addrstr, $useimap, $charset );
- $addrstr(строка) (обязательный)
- The address list string.
- $useimap(true|false|null)
- Deprecated in PHPMailer 6.11.0. Truthy values request the deprecated IMAP parser and trigger a deprecation warning.
По умолчанию:null - $charset(строка)
- The charset to use when decoding the address list string.
По умолчанию:self::CHARSET_ISO88591
Заметки
| Смотрите: https://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation |
Код PHPMailer::parseAddresses() PHPMailer::parseAddresses WP 7.1.2
public static function parseAddresses($addrstr, $useimap = null, $charset = self::CHARSET_ISO88591)
{
if ($useimap == true) {
trigger_error(self::lang('deprecated_argument') . '$useimap', E_USER_DEPRECATED);
}
$addresses = [];
if ($useimap == true && function_exists('imap_rfc822_parse_adrlist')) {
//Use this built-in parser if it's available
// phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.imap_rfc822_parse_adrlistRemoved -- wrapped in function_exists()
$list = imap_rfc822_parse_adrlist($addrstr, '');
// Clear any potential IMAP errors to get rid of notices being thrown at end of script.
// phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.imap_errorsRemoved -- wrapped in function_exists()
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;
}