I'm using the following code to check email addresses.
Code: Select all
//---Connect to mail server and check e-mail address------------------
$Connect = fsockopen ( $ConnectAddress, 25 );
//Gives this error when domain exists but no mx:
//Warning: fsockopen() [function.fsockopen]: unable to connect to mx.somewhere.com:25
//(Connection refused) in /xxx/requestcontact.php on line 26
if ($Connect) {
if (ereg("^220", $Out = fgets($Connect, 1024))) {
fputs ($Connect, "HELO $HTTP_HOST\r\n");
$Out = fgets ( $Connect, 1024 );
fputs ($Connect, "MAIL FROM: <{$Email}>\r\n");
$From = fgets ( $Connect, 1024 );
fputs ($Connect, "RCPT TO: <{$Email}>\r\n");
$To = fgets ($Connect, 1024);
fputs ($Connect, "QUIT\r\n");
fclose($Connect);
if (!ereg ("^250", $From) || !ereg ( "^250", $To )) {
$result[0]=false;
$result[1]="Address not valid; Server rejected address";
return $result;
}
} else {
$result[0] = false;
$result[1] = "No response from server";
return $result;
}
} else {
$result[0]=false;
$result[1]="Can not connect E-Mail server.";
return $result;
}If I encapsulate that code in an if statement like this
Code: Select all
If (fsockopen ( $ConnectAddress, 25 )) {
$Connect = fsockopen ( $ConnectAddress, 25 );
//rest of code here
} else {
$result[0]=false;
$result[1]="Can not connect E-Mail server.";
return $result;
}Edit: Correction that does not work, Why?????
How can I get around the connection refusal? so the code continues to the next if statement?
All explainations gratefully received as I don't really understand what's happening.
Thanking you in anticipation,
blade