I’ve used the function below before to check the validity of an email
address. However, the DNS check is now always returning false regardless –
even if the email address is valid. I call the function like:

if (IsEmailAddrValid($HTTP_POST_VARS["emailaddress"], true))

What I don’t understand is what DNS server is PHP using to find this
information? I’m not running a local DNS server and I’m sitting behind a
proxy firewall, is this what’s causing the DNS check to fail? If so is there
a work around to manually provide an IP address for the DNS server to use,
etc?

Thanks

James


function IsEmailAddrValid($email, $check_dns = false)
{ 
  if( 
      (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) 
      || 
      (preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/', 
$email)) 
    ) 
  { 
    if($check_dns) 
    { 
      $host = explode('@', $email);
      // Check for MX record 
      if( checkdnsrr($host[1], 'MX') ) return true; 
      // Check for A record 
      if( checkdnsrr($host[1], 'A') ) return true; 
      // Check for CNAME record 
      if( checkdnsrr($host[1], 'CNAME') ) return true; 
    } 
    else 
    { 
      return true; 
    } 
  } 
  return false; 
}
 
 

Reply via email to