public function PHPMailer::punyencodeAddress
Search API
5.x PHPMailer.php | public PHPMailer::punyencodeAddress($address) |
Converts IDN in given email address to its ASCII form, also known as punycode, if possible. Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet. This function silently returns unmodified address if:
- No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form)
- Conversion to punycode is impossible (e.g. required PHP functions are not available) or fails for any reason (e.g. domain contains characters not allowed in an IDN).
Parameters
string $address The email address to convert:
Return value
string The encoded address in ASCII form
See also
PHPMailer::$CharSet
1 call to PHPMailer::punyencodeAddress()
- PHPMailer::preSend in inc/
PHPMailer/ src/ PHPMailer.php - Prepare a message for sending.
File
- inc/
PHPMailer/ src/ PHPMailer.php, line 1336
Class
- PHPMailer
- PHPMailer - PHP email creation and transport class.
Namespace
PHPMailer\PHPMailerCode
public function punyencodeAddress($address)
{
// Verify we have required functions, CharSet, and at-sign.
$pos = strrpos($address, '@');
if (static::idnSupported() and
!empty($this->CharSet) and
false !== $pos
) {
$domain = substr($address, ++$pos);
// Verify CharSet string is a valid one, and domain properly encoded in this CharSet.
if ($this->has8bitChars($domain) and @mb_check_encoding($domain, $this->CharSet)) {
$domain = mb_convert_encoding($domain, 'UTF-8', $this->CharSet);
//Ignore IDE complaints about this line - method signature changed in PHP 5.4
$errorcode = 0;
$punycode = idn_to_ascii($domain, $errorcode, INTL_IDNA_VARIANT_UTS46);
if (false !== $punycode) {
return substr($address, 0, $pos) . $punycode;
}
}
}
return $address;
}