Created
December 22, 2008 15:23
-
-
Save PixelRobot/39015 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function checkEmail($email){ | |
// checks proper syntax | |
if( !preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)){ | |
return false; | |
} | |
// gets domain name | |
list($username,$domain)=split('@',$email); | |
// checks for if MX records in the DNS | |
$mxhosts = array(); | |
if(!getmxrr($domain, $mxhosts)){ | |
// no mx records, ok to check domain | |
if (!fsockopen($domain,25,$errno,$errstr,30)){ | |
return false; | |
}else{ | |
return true; | |
} | |
}else{ | |
// mx records found | |
foreach ($mxhosts as $host){ | |
if (fsockopen($host,25,$errno,$errstr,30)){ | |
return true; | |
} | |
} | |
return false; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment