Created
March 5, 2011 16:49
-
-
Save zackdouglas/856497 to your computer and use it in GitHub Desktop.
Simple Email Validation with DNS Check
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 | |
/** | |
* checks syntax and optionally DNS records for the provided email address string | |
*/ | |
function validateEmail($email, $and_dns=true) { | |
if (!filter_var($em, FILTER_VALIDATE_EMAIL)) { | |
return false; | |
} | |
if (!$and_dns) { | |
return true; | |
} | |
$dom = substr($em, strpos($em, '@') + 1); | |
$fake_uri = "http://$dom/"; | |
$parts = parse_url($fale_uri); | |
$dom = $parts['host']; | |
return checkdnsrr($dom); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment