Created
August 12, 2013 04:59
-
-
Save datibbaw/6208340 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Validates an email domain part | |
* | |
* @see http://www.faqs.org/rfcs/rfc2821.html - chapter 5 | |
*/ | |
function validate_email_domain($domain, $allow_a = true, $max_cname_recursion = -1) | |
{ | |
$flags = DNS_CNAME | DNS_MX | ($allow_a ? DNS_A | DNS_AAAA : 0); | |
if (false === ($rr_list = dns_get_record($domain, $flags))) { | |
throw new TPE_DNS_Exception("Could not validate domain $domain"); | |
} | |
$have_a_record = false; | |
foreach ($rr_list as $rr) { | |
if ('CNAME' == $rr['type'] && $max_cname_recursion) { | |
/** | |
* If a CNAME record is found instead, | |
* the resulting name is processed as if it were the initial name. | |
**/ | |
return $this->validate_email_domain($rr['target'], $allow_a, $max_cname_recursion - 1); | |
} elseif ('MX' ==$rr['type']) { | |
return true; | |
} elseif ('A' == $rr['type'] || 'AAAA' == $rr['type']) { | |
$have_a_record = true; | |
} | |
} | |
/** | |
* If no MX records are found, but an A RR is found, the A RR is treated as | |
* if it was associated with an implicit MX RR, with a preference of 0, | |
* pointing to that host | |
* | |
* This part of the specification is not used here | |
**/ | |
return $have_a_record; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment