SpinningKASi
asked on
Check if E-Mail exists
Is there a chance to check an email-adress with php? Not only if the domain exists by checking the mailservers, also checking if the recipient is real by testing the reply code from the mail server for the 550 (no recipient)?
ASKER
Looks good, but the function "verifyemail_localhost()" could not be found :(
Maybe I´m too blind to see it... Which funtion I have to use to check the mail?
Maybe I´m too blind to see it... Which funtion I have to use to check the mail?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In addition to 127.0.0.1, check the email address itself to see if it is you or not. Spammers love doing this too!
Did any of this help you? If so, please award a grade to close this question.
function verifyemail_validateemail(
{
if (!preg_match("/^([\w|\.|\-
return false;
return true;
}
function verifyemail_validatehost($
{
if (!verifyemail_validateemai
return false;
list($local,$domain) = explode("@",$email,2);
$mxhosts = array();
if(!checkdnsrr($domain, "MX") || !getmxrr($domain, $mxhosts))
return false;
if ($return_mxhost)
return $mxhosts;
return true;
}
function verifyemail_validateexists
{
$mxhosts = verifyemail_validatehost($
if (!is_array($mxhosts))
return false;
$found = false;
$localhost = verifyemail_localhost();
$mxsize = sizeof($mxhosts);
for($i=0; $i<$mxsize; $i++)
{
$socket = fsockopen($mxhosts[$i], 25);
if(!$socket) continue;
$foo = fgets($socket, 4096);
# 220 <domain> Service ready
if(!preg_match("/^220/i", $foo))
{
verifyemail_closesocket($s
continue;
}
fputs($socket, "HELO ".$localhost."\r\n");
$foo = fgets($socket);
while (preg_match("/^220/i", $foo))
$foo = fgets($socket, 4096);
fputs($socket, "VRFY ".$email."\r\n");
$foo = fgets($socket, 4096);
# 250 Requested mail action okay, completed
if(preg_match("/^250/i", $foo))
{
$found = true;
verifyemail_closesocket($s
break;
}
# 550 Requested action not taken: mailbox unavailable [E.g., mailbox not found, no access]
if(preg_match("/^550/i", $foo))
{
verifyemail_closesocket($s
continue;
}
fputs($socket, "MAIL FROM: <".$email.">\r\n");
$foo = fgets($socket, 4096);
fputs($socket, "RCPT TO: <".$email.">\r\n");
$foo = fgets($socket, 4096);
# 250 Requested mail action okay, completed
# 251 User not local; will forward to <forward-path>
if(preg_match("/^[250|251]
{
$found = true;
verifyemail_closesocket($s
break;
}
verifyemail_closesocket($s
}
return $found;
}
function verifyemail_closesocket($s
{
fputs($socket, "QUIT\r\n");
fclose($socket);
return true;
}
?>