Searching DNS records
| From: | James Duncan | Date: | Fri, 02 Mar 2001 22:18:46 +0000 |
| Subject: | Searching DNS records | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-5796@lists.php.net to get a copy of this message | ||
Ive 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 dont understand is what DNS server is PHP using to find this
information? Im not running a local DNS server and Im sitting behind a
proxy firewall, is this whats 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;
}