-
-
Save hasibomi/6849d3c72ff1b6d7c708f41ccfbe8ef1 to your computer and use it in GitHub Desktop.
How to validate an email address with PHP
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 | |
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('[email protected]'); // Returns TRUE | |
validEmail('[email protected]'); // Returns FALSE | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment