For some reason this and the other DNS lookup functions seem to be really slow on my Linux box. I've checked several things and have no explanation.
As a work-around, I gave in and just used a system call to dig:
<?php
CheckMX("fakedomain.org");
CheckMX("hotmail.com");
function CheckMX($domain) {
exec("dig +short MX " . escapeshellarg($domain),$ips);
if($ips[0] == "") {
print "MX record found for $domain not found!\n";
return FALSE;
}
print "MX Record for $domain found\n";
return TRUE;
}
?>
Output:
MX record found for fakedomain.org not found!
MX Record for hotmail.com found
As someone else pointed out, it is prudent to check to see if the TLD has an IP address if the MX record is not found.