Sunday, December 26, 2010

A “Revolutionary” Way to Validate Email Input

I’m not talking about confirming email, where you have to make sure that the
user owns an email address, but I am talking about a way to confirm that an email entered will probably work
WITHOUT succumbing to regex, AND it’s relatively quick!

[codesyntax
lang=php]
function validate_email($email)
{
$email_parts =
explode("@",$email);
if(count($email_parts)) != 2) { return FALSE; } // You can only have one @
in an email address.
$domain = $email_parts[1];
if(!getmxrr($domain,$array)) { return
FALSE; } // This domain doesn't have any MX Records.
return TRUE; // Everything else is 'valid.'
}
[/codesyntax]