How to validate email id using checkdnsrr() function in PHP

Are you tired of dummy email id’s being used on your website. Like, etc ?

You can use PHP function


It checks whether the dns value is valid or not. Only the email id with valid domain name will be accepted 😉

This is inspired from the original post of one of our Author SNEHAL. Originally posted on his blog.

checkdnsrr() function will take an email address and performs a DNS lookup on the specified host (either a hostname or IP address). You can use this function before sending emails. The function will return an error informing the user that the domain related to email address probably doesn’t exist.

This function can look up the following record types:

bool checkdnsrr (string $host [, string $type = “MX” ] )

string $host: Hostname or IP address to check
string $type (optional): Type of record to check for

Record Type Details

A : Address: Defined in RFC 1035.
ALL : Any of the valid types.
CNAME : Canonical Name: Defined in RFC 1035.
MX : Mail Exchanger: Defined in RFC 1035.
NS : Name Server: Defined in RFC 1035.
PTR : Pointer: Defined in RFC 1035.
SOA : Start of Authority: Defined in RFC 1035.

Example :

$email = "";
echo validate_email($email);

function validate_email($email){

$exp = "/^(([^()[\]\\.,;:\s@\”]+(\.[^()[\]\\.,;:\s@\”]+)*)|(\”.+\”))@(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/”;


//array_pop : returns the last value of an array.
return “Valid Email”;
return “Invalid Email”;


return “Invalid ID”;



Please provide your feedback and suggestions in comment section. To get latest Update follow our blog.


4 thoughts on “How to validate email id using checkdnsrr() function in PHP

  1. Hello! This is kind of off topic but I need some guidance from an established blog. Is it difficult to set up your own blog? I’m not very techincal but I can figure things out pretty quick. I’m thinking about making my own but I’m not sure where to begin. Do you have any tips or suggestions? Appreciate it For news and guidance about how to Create A Website visit


    • Hi.. you don’t really need to have web development knowledge to create a blog.. you can create you free blog from or There are many others too who offers this facility but is best


  2. L’idée est bonne, mais ce formulaire refusera tous les nouveaux domaines avec un suffixe en .paris, .voyage ou des centaines d’autres…. Par ailleurs lisez la doc: il n’y a aucune obligation à définir un champs MX pour qu’un domaine puisse recevoir des email.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s