diff --git a/src/Validation/DNSCheckValidation.php b/src/Validation/DNSCheckValidation.php index d9ffaad..214d4f4 100644 --- a/src/Validation/DNSCheckValidation.php +++ b/src/Validation/DNSCheckValidation.php @@ -123,9 +123,20 @@ protected function checkDns($host) { $variant = INTL_IDNA_VARIANT_UTS46; - $host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.') . '.'; + $host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.'); - return $this->validateDnsRecords($host); + $hostParts = explode('.', $host); + $host = array_pop($hostParts); + + while (count($hostParts) > 0) { + $host = array_pop($hostParts) . '.' . $host; + + if ($this->validateDnsRecords($host)) { + return true; + } + } + + return false; } diff --git a/tests/EmailValidator/Validation/DNSCheckValidationTest.php b/tests/EmailValidator/Validation/DNSCheckValidationTest.php index ed9dd84..610a295 100644 --- a/tests/EmailValidator/Validation/DNSCheckValidationTest.php +++ b/tests/EmailValidator/Validation/DNSCheckValidationTest.php @@ -21,6 +21,7 @@ public function validEmailsProvider() return [ // dot-atom ['Abc@ietf.org'], + ['Abc@fake.ietf.org'], ['ABC@ietf.org'], ['Abc.123@ietf.org'], ['user+mailbox/department=shipping@ietf.org'], @@ -149,4 +150,4 @@ public function getRecords(string $host, int $type): DNSRecords $validation->isValid('example@invalid.example.com', new EmailLexer()); $this->assertEquals($expectedError, $validation->getError()); } -} \ No newline at end of file +}