Created
October 8, 2013 19:40
-
-
Save marcelsud/6890333 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 validateEmail($email) | |
| { | |
| if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { | |
| throw new InvalidArgumentException("Invalid email"); | |
| } else { | |
| $domain = end(explode('@', $email)); | |
| if (!checkdnsrr($domain, 'MX')) { | |
| throw new InvalidArgumentException("Invalid email"); | |
| } | |
| return true; | |
| } | |
| } | |
| $emails = array("[email protected]", "[email protected]"); | |
| foreach ($emails as $email) { | |
| try { | |
| if (validateEmail($email)) { | |
| echo "Valid email" . PHP_EOL; | |
| } | |
| } catch (InvalidArgumentException $e) { | |
| echo $e->getMessage() . PHP_EOL; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment