Check for valid e-mail

First does a crude check to see if everything before the @ is valid, and that the part after contains a . (dot) using preg_match(). If it is, check if the domain resolves using the checkdnsrr() function.

if (!preg_match("/^[a-z0-9._-]+@(.+[.].+)$/i", $email, $check)) {
	echo 'Invalid email address.';
} elseif (!checkdnsrr($check[1], "ANY")) {
	echo 'Invalid email address.';
}
php/snippets/validemail.txt · Last modified: 2007/01/21 21:46 by zyberdog