Skip to content

Instantly share code, notes, and snippets.

@robhimself82
Created January 1, 2012 11:38
Show Gist options
  • Select an option

  • Save robhimself82/1547105 to your computer and use it in GitHub Desktop.

Select an option

Save robhimself82/1547105 to your computer and use it in GitHub Desktop.
PHP Email Validation
<?
if (isset($_POST['action']) && !empty($_POST['action'])) {
$action = $_POST['action'];
switch($action) {
case 'validate_domain':
// If we're not passing in an email address, automatically return false.
if (!isset($_POST['email']) || empty($_POST['email'])) return false;
return domain_exists($_POST['email']);
break;
}
}
function domain_exists($email, $recordType = 'MX') {
list($user, $domain) = split('@', $email);
echo checkdnsrr($domain, $recordType) ? "true" : "false";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment