Is there anyway to ping an email address or something such like to check with it is a real working address. I'm not talking about regex or php validate filters etc, but actually checking the address exists??
Asked
Active
Viewed 1.5k times
5
-
7Send an email and have them click a link to validate? A good deal of mail servers are not configured to respond if an email address does not exist, and even the ones that do, don't always send an error back. – Jared Farrish Mar 25 '11 at 09:22
-
you can ping a server, not an email address. But even if you will ping it, it doesn't mean email address is real. – usoban Mar 25 '11 at 09:23
-
3possible duplicate of [How to check if an email address exists without sending an email?](http://stackoverflow.com/questions/565504/how-to-check-if-an-email-address-exists-without-sending-an-email) – Toon Krijthe Mar 25 '11 at 09:28
-
1All spammers whould love that ;) – Haza Mar 25 '11 at 09:29
3 Answers
3
It is possible, but not reliable to connect to the recipient mailserver and offer a mail, prompting the mailserver to reject or accept the mail. Not all mail servers will check the validity of adresses, so don't rely on it. Similar question here.
-
1In addition to the lack of reliability, it might also have bad effects on performance and user experience, because you have to open a socket connection with some timout. – jm_toball Mar 25 '11 at 09:50
2
useful function for check hostname exist(90% worked!):
function validate_email($email)
{
if(!preg_match ("/^[\w\.-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]+$/", $email))
return false;
list($prefix, $domain) = explode("@",$email);
if(function_exists("getmxrr") && getmxrr($domain, $mxhosts))
return true;
elseif (@fsockopen($domain, 25, $errno, $errstr, 5))
return true;
else
return false;
}

Javad Masoumi
- 347
- 2
- 5
1
You could check to see if there are MX records for the corresponding domain: getmxrr() http://php.net/manual/en/function.getmxrr.php
But i would suggest using a two part validation:
- first a simple
regex for plain validation of input
- then a simple
check to see if the tld is valid
// pattern was taken from PHP's own source
$pattern = "/^((\\\"[^\\\"\\f\\n\\r\\t\\b]+\\\")|([A-Za-z0-9_][A-Za-z0-9_\\!\\#\\$\\%\\&\\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]*(\\.[A-Za-z0-9_\\!\\#\\$\\%\\&\\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]*)*))@((\\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9])(([A-Za-z0-9\\-])*([A-Za-z0-9]))?(\\.(?=[A-Za-z0-9\\-]))?)+[A-Za-z]+))$/D";
if (preg_match($pattern, $email)) {
/**
* allow ip address as domain OR it should be a valid TLD
*/
$long = ip2long(substr($email, strrpos($email, '@')+1));
return (($long !==FALSE && $long>-1)
|| isValidTld(substr($email, strrpos($email, '.')+1)));
}
This is still no garantee that it works but other than sending an email and catching possible bounces ... this is pretty much (aside from the mx-check) it...

Gekkie
- 996
- 9
- 24