Skip to content

Instantly share code, notes, and snippets.

@zackdouglas
Created March 5, 2011 16:49
Show Gist options
  • Save zackdouglas/856497 to your computer and use it in GitHub Desktop.
Save zackdouglas/856497 to your computer and use it in GitHub Desktop.
Simple Email Validation with DNS Check
<?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