iBlog random » email http://blog.zurka.us Just another WordPress weblog Tue, 28 May 2013 20:28:47 +0000 en-US hourly 1 http://wordpress.org/?v=3.6 Email validation with PHP http://blog.zurka.us/email-validation-with-php/ http://blog.zurka.us/email-validation-with-php/#comments Sun, 26 Oct 2008 20:09:30 +0000 nasal http://blog.zurka.us/?p=628

This script is more accurate then a normal validation script. After checking if the email is correctly typed in (@) it checks the domain validity by checking it’s dns records (MX, A and CNAME). A piece of the regex is cut because of my sidebar but if you copy/paste everything you should see it :)

function check_email($email) {
	if( (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) ||
 		(preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) ) {
 		$host = explode('@', $email);
 		if(checkdnsrr($host[1].'.', 'MX') ) return true;
 		if(checkdnsrr($host[1].'.', 'A') ) return true;
 		if(checkdnsrr($host[1].'.', 'CNAME') ) return true;
 	}
 	return false;
}
]]>
http://blog.zurka.us/email-validation-with-php/feed/ 1