Validate the mx record using php checkdnsrr

Please post your suggestions or any hacks you have made here

Validate the mx record using php checkdnsrr

Postby Kannan1976 » Thu Jan 21, 2010 8:43 am

Hi there,

Is there a way i can use the checkdnsrr in php to validate the users email address in Chrono Forms? I found this code but can it be integrated with CF onsubmit.

Code: Select all
$email = '{Email}';

if(verify_email($email)){

    // E-mail address looks to be in the proper format
    // lets check the MX records

    if(verify_email_dns($email)){

        // E-mail passed both checks
        echo 'Success - E-mail address appears to be valid.';

    } else {

        // E-mail is invalid, no MC record
        echo 'Error - E-mail domain does not have an MX record.';

    }

} else {

    // E-mail inst formatted correctly
    // so we don't even check its MX record
    echo 'Error - E-mail address appears to be invalid.';

}

// Our function to filter our bogus formatted addresses
function verify_email($email){

    if(!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/',$email)){
        return false;
    } else {
        return $email;
    }
}

// Our function to verify the MX records
function verify_email_dns($email){

    // This will split the email into its front
    // and back (the domain) portions
    list($name, $domain) = split('@',$email);

    if(!checkdnsrr($domain,'MX')){

        // No MX record found
        return false;

    } else {

        // MX record found, return email
        return $email;

    }
}



If it's possible, where can i place this code?

Thanks.
Kannan1976
Fresh Boarder
 
Posts: 1
Joined: Wed Dec 30, 2009 1:06 am

Re: Validate the mx record using php checkdnsrr

Postby GreyHead » Thu Jan 21, 2010 9:06 am

Hi Kannan1976,

Looks like the Server-side validation codebox is a good place for this.

You'll need to restructure the code a little so that it meets the validation code requirements and returns a message only if it fails
Code: Select all
$email = JRequest::getVar('email', '', 'post');
if ( !$email ) {
  return 'An e-mail is required.';
}
if ( !verify_email($email) ) {
  // E-mail isn't formatted correctly
  return echo 'Error - E-mail address appears to be invalid.';
}

// lets check the MX records
if ( !verify_email_dns($email) ) {
  // E-mail is invalid, no MC record
  return 'Error - E-mail domain does not have an MX record.';
}
// E-mail passed all checks

// Our function to filter our bogus formatted addresses
function verify_email($email)
{
  return preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/',
}

// Our function to verify the MX records
function verify_email_dns($email)
{
  // This will split the email into its front
  // and back (the domain) portions
  list($name, $domain) = split('@', $email);

  return checkdnsrr($domain, 'MX');
}
?>
Not checked and may well need debugging

Bob
Bob Janes ChronoForms Support
*** The ChronoForms book is out NOW ***
ImageClick for more info
User avatar
GreyHead
Administrator
Administrator
 
Posts: 14754
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany


Return to ChronoForms Suggestions & Hacks

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests

 

Who is online

In total there is 1 user online :: 1 registered, 0 hidden and 0 guests (based on users active over the past 15 minutes)
Most users ever online was 109 on Mon Jul 05, 2010 6:59 pm

Users browsing this forum: Yahoo [Bot] and 0 guests

Current time

It is currently Fri Sep 10, 2010 11:43 am