$stopTime = time() + 10;
$gotResponse = FALSE;
while(TRUE)
{
//try to get a line from mail server
$line = fgets($fp, 1024);
if(substr($line, 0, 3) == "220")
{
//reset timer
$stopTime = time() + 10;
$gotResponse = TRUE;
}
elseif(($line == "") AND ($gotResponse))
{
break;
}
elseif(time() > $stopTime)
{
break;
}
}
if(!$gotResponse)
{
//this host was unresponsive, but
//maybe the next will be better
continue;
}
set_socket_blocking ($fp, TRUE);
//sign in
fputs($fp, "HELO $SERVER_NAME\r\n");
fgets($fp, 1024);
//set from
fputs($fp, "MAIL FROM: <info@$domain>\r\n");
fgets($fp, 1024);
//try address
fputs($fp, "RCPT TO: <$address>\r\n");
$line = fgets($fp, 1024);
//close connection