mmucklo raises a valid point, however the function to use would be getmxrr() in the simplest case, or alternatively checkdnsrr() if you so wish; getdnsrr() does not exist.
On another note, it can be a pain (when iterating with while loops for example) that on failure gethostbyname() returns the hostname, rather than FALSE. You could wrap it in a simple user function, to "correct" this:
<?php
function fixed_gethostbyname ($host) {
// Try the lookup as normal...
$ip = gethostbyname($host);
// ...but if it fails, FALSE is returned instead of the unresolved host
if ($ip != $host) { return $ip; } else return false;
}
?>