Skip to content

Instantly share code, notes, and snippets.

@alexmazaltov
Forked from anxp/email_validation_simple.php
Created September 28, 2020 06:35
Show Gist options
  • Save alexmazaltov/d382efe2b11bff1b07f3c1b62630d308 to your computer and use it in GitHub Desktop.
Save alexmazaltov/d382efe2b11bff1b07f3c1b62630d308 to your computer and use it in GitHub Desktop.
Simple email address validation - check syntax and MX record existing.
<?php
function _nxte_redeem_is_email_valid($email) {
if (empty ($email)) {return false;}
list($user_name, $mail_domain) = explode('@', $email);
if (empty($user_name) || empty($mail_domain)) {return false;}
$is_syntax_ok = (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
$is_MX_exists = checkdnsrr($mail_domain, 'MX');
return ($is_syntax_ok && $is_MX_exists);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment