PHP E-Mail Address Validation
13
This little function will split an e-mail address passed to it at the @ sign, and make sure that there is a valid e-mail server at the other end =)
//------------------------------------------------------------------------------------------------------
//VerifyEmailAddress($EMail) VerifyEmailAddress($EMail)
//------------------------------------------------------------------------------------------------------
// What it does-
// Verifies an e-mail address by splitting it at '@' and pinging the domain.
//
// Changes -
// August 4th, 2006 - RaX - Changed Split() to Explode() for speed.
// August 3rd, 2006 - RaX - Created.
//
//------------------------------------------------------------------------------------------------------
function VerifyEmailAddress($EMail){
list($User, $Domain) = explode("@", $EMail);
$Result = checkdnsrr($Domain, 'MX');
return($Result);
}






I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?
Regards,
Kumar S
GuyFromChennai.com
Via http://us3.php.net/checkdnsrr, checkdnsrr() will return either TRUE or FALSE; true for success, and false for everything else.
If you do a list($var1, $var2) = explode('@', $string) and there is no '@', then $var2 will be null.
If you then turn around and do checkdnsrr($var2, 'MX'), then the result will be FALSE; as expected. So therefore, this snippet does work and does work correctly.
Will this script work on a Windows server?
http://bytemycode.com/snippets/snippet/377/
I would add the code above to this script as a revision or comment.