function DNSCheckValidation::isValid
Overrides EmailValidation::isValid
File
-
vendor/
egulias/ email-validator/ src/ Validation/ DNSCheckValidation.php, line 75
Class
Namespace
Egulias\EmailValidator\ValidationCode
public function isValid(string $email, EmailLexer $emailLexer) : bool {
// use the input to check DNS if we cannot extract something similar to a domain
$host = $email;
// Arguable pattern to extract the domain. Not aiming to validate the domain nor the email
if (false !== ($lastAtPos = strrpos($email, '@'))) {
$host = substr($email, $lastAtPos + 1);
}
// Get the domain parts
$hostParts = explode('.', $host);
$isLocalDomain = count($hostParts) <= 1;
$isReservedTopLevel = in_array($hostParts[count($hostParts) - 1], self::RESERVED_DNS_TOP_LEVEL_NAMES, true);
// Exclude reserved top level DNS names
if ($isLocalDomain || $isReservedTopLevel) {
$this->error = new InvalidEmail(new LocalOrReservedDomain(), $host);
return false;
}
return $this->checkDns($host);
}