function checkEmail($email) {
// Regex for checking email format
$regexp = "^([_a-z0-9-]+)(.[_a-z0-9-]+)*@([a-z0-9-]+)(.[a-z0-9-]+)*(.[a-z]{2,4})$";
$valid = 0;
// Validate the email format
if (eregi($regexp, $email)) {
//split email address if its valid so we can check domain
list($username,$tld) = split("@",$email);
// Validate the domain
if (getmxrr($tld,$mxrecords))
$valid = 1;
} else {
$valid = 0;
}
return $valid;
}
The big picture: validate the mail with regex, then fetch the MX records for the domain, if the mx records exists the mail is somewhat valid.
Enjoy!
If this has been useful you should give me a beer


3 responses
Do you want to comment?
Comments RSS and TrackBack Identifier URI ?
Trackbacks