Search code examples
phpspamverification

How can I make checkdnsrr use Spamhaus.org instead of MX?


I've been given this code to utilize to test out, and verify if email addresses coming in are valid. I know this works, but again with all gifts during Christmas the price tag has been removed.

In my case, the instructions have been stripped. I am taking by what I see in this script that the "MX" is telling the script to use the MX Verify database... do I just replace or add next to it ,"spamhaus.org" to make it work? Or is it more than that?

I am not on a windows machine as my server so I don't need to worry checkdnsrr not working.

Also, is there a better version of this script out there? I'm curious because unthankfully this part of PHP coding is new to me.

Thanks in advance.

// take a given email address and split it into the username and domain.
list($userName, $mailDomain) = split("@", $email);
if (checkdnsrr($mailDomain, "MX")) {
  // this is a valid email domain!
}
else {
  // this email domain doesn't exist! bad dog! no biscuit!
} 

Solution

  • From http://php.net/manual/en/function.checkdnsrr.php the only supported methods for checkdnsr are A, MX, NS, SOA, PTR, CNAME, AAAA, A6, SRV, NAPTR, TXT or ANY. you can't add in a custom URL.

    Try:

    $host = '64.53.200.156';
    
    $rbl  = 'sbl-xbl.spamhaus.org';
    // valid query format is: 156.200.53.64.sbl-xbl.spamhaus.org
    $rev = array_reverse(explode('.', $host));
    
    $lookup = implode('.', $rev) . '.' . $rbl;
    
    if ($lookup != gethostbyname($lookup)) {
        echo "ip: $host is listed in $rbl\n";
    } else {
        echo "ip: $host NOT listed in $rbl\n";
    }