Posted By

NaetoH on 02/06/13


Tagged

email check DNS


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

NaetoH


Check email validity with domain name


 / Published in: PHP
 

Check the email validity with filter_var and checkdns

  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  

You need to login to post a comment.