Skip to content

Instantly share code, notes, and snippets.

@tcarlsen
Created September 13, 2010 12:18
Show Gist options
  • Save tcarlsen/577213 to your computer and use it in GitHub Desktop.
Save tcarlsen/577213 to your computer and use it in GitHub Desktop.
function checkEmail($email) {
// checks proper syntax
if(preg_match("/^([a-z])([a-z0-9._])+([a-z0-9])\@([a-z0-9])*([a-z])+(-[a-z])*([a-z0-9])*(\.([a-z0-9])*([a-z])+(-[a-z])*([a-z0-9])*)+$/i" , $email)) {
// gets domain name
list($username,$domain)=split('@',$email);
// checks for if MX records in the DNS
if(!checkdnsrr($domain, 'MX')) {
return false;
}
// attempts a socket connection to mail server
if(!fsockopen($domain,25,$errno,$errstr,30)) {
return false;
}
return true;
}
return "hmm";
}
@henrikbjorn
Copy link

Du skal huske at lukke connection igen ellers vil du have en resource der ligger og tager plads etc.
Det burde være nok at checke dns du behøver ikke lave en connection til serveren også.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment