Skip to content

Instantly share code, notes, and snippets.

@hasibomi
Forked from MikeRogers0/validate-email.php
Created February 22, 2018 18:55
Show Gist options
  • Save hasibomi/6849d3c72ff1b6d7c708f41ccfbe8ef1 to your computer and use it in GitHub Desktop.
Save hasibomi/6849d3c72ff1b6d7c708f41ccfbe8ef1 to your computer and use it in GitHub Desktop.
How to validate an email address with PHP
<?php
function validEmail($email){
// Check the formatting is correct
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
return FALSE;
}
// Next check the domain is real.
$domain = explode("@", $email, 2);
return checkdnsrr($domain[1]); // returns TRUE/FALSE;
}
// Example
validEmail('real@hotmail.com'); // Returns TRUE
validEmail('fake@fakedomain.com'); // Returns FALSE
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment