Hi, I am trying to validate email address's on my registration form. Everything works great except for checkdnsrr function. I was wondering can anyone help with this. I never used checkdnsrr before.

Here is the code I'm using:

//set flag that sais pwd is OK
    $pwdOK = true;
    //trim whitespace
    $_POST['pwd'] = trim($_POST['pwd']);
    if (strlen($_POST['pwd']) < 3) {
        $error['pwd_length'] = 'Password must be at least 3 charecters';
        $pwdOK = false;
    }
//validate email
if(!function_exists('checkdnsrr'))
{
    function checkdnsrr($localhost, $recType = '')
    {
     if(!empty($localhost)) {
       if( $recType == '' ) $recType = "MX";
       exec("nslookup -type=$recType $hostName", $result);
       // check each line to find the one that starts with the host
       // name. If it exists then the function succeeded.
       foreach ($result as $line) {
         if(eregi("^$hostName",$line)) {
           return true;
         }
       }
       // otherwise there was no mail handler for the domain
       return false;
     }
     return false;
    }
}

Thanks.

Recommended Answers

All 2 Replies

I haven't used that function myself, but I can tell you that you haven't provided workable arguments here.

function checkdnsrr($localhost, $recType = '')

First of all, the function description can be found here:
http://us3.php.net/manual/en/function.checkdnsrr.php
It checks DNS records. If you are using a localhost, there is no DNS
Secondly, it wants a type, but you have null. it defaults to MX, so:

function checkdnsrr('someRealSiteName.com');

should work.

Thanks, I am new to email validation. I was also wondering of other ways to validate emails.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.