Validate Email Address in PHP

 

Now a days most important for  any portal is validating the user email addresses.  We have a lot of ways are there for checking the email format.

Now in this article, we will show you how to validate the email address using the “checkdnsrr” function.

checkdnsrr — Check DNS records corresponding to a given Internet host name or IP address

First the general syntax of the string is checked with a regular expression and after that the domain substring (after the ‘@’) is checked using the ‘checkdnsrr‘ function.

function validate_email($email){
  $exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";
  if(eregi($exp,$email)){
   if(checkdnsrr(array_pop(explode("@",$email)),"MX")){
     return true;
   }else{
    return false;
   }
  }else{
    return false;
  }
}

84 Comments

  1. www.sportsentire.com

    thanks useful for our site,trying a new email validation mechanism.This worked perfectly

Leave a Reply