Check email validity with domain name


/ Published in: PHP
Save to your folder(s)

Check the email validity with filter_var and checkdns


Copy this code and paste it in your HTML
  1. function checkEmail($email) {
  2. $validate = filter_var($email, FILTER_VALIDATE_EMAIL);
  3. if ($validate) {
  4. $dns = substr(strchr($email, '@'), 1);
  5. if (checkdnsrr($dns, "MX")) {
  6. return array('errors' => false, 'message' => 'good email');
  7. } else {
  8. return array('errors' => true, 'message' => "Domain name for email doesn't exist");
  9. }
  10. } else {
  11. return array('errors' => true, 'message' => "Invalid email");
  12. }
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.