Skip to content

Instantly share code, notes, and snippets.

@marcelsud
Created October 8, 2013 19:40
Show Gist options
  • Select an option

  • Save marcelsud/6890333 to your computer and use it in GitHub Desktop.

Select an option

Save marcelsud/6890333 to your computer and use it in GitHub Desktop.
<?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