//make sure the domain has a mail exchanger
if(checkdnsrr($domain, "MX"))
{
//get mail exchanger records
if(!getmxrr($domain, $mxhost, $mxweight))
{
$error =
"Could not retrieve mail
exchangers!
\n";
return(FALSE);
}
}
else
{
//if no mail exchanger, maybe the host
itself
//will accept mail
$mxhost[] = $domain;
$mxweight[] = 1;
}
//create sorted array of hosts
for($i = 0; $i count($mxhost); $i++)
{
$weighted_host[($mxweight[$i])] =
$mxhost[$i];
}
ksort($weighted_host);
//loop over each host
foreach($weighted_host as $host)
{
//connect to host on SMTP port
if(!($fp = fsockopen($host, 25)))
{
//couldn't connect to this host, but
//the next might work
continue;
}
/*
skip over 220 messages
give up if no response for 10 seconds
*/
set_socket_blocking($fp, FALSE);