PHP Email address validation with Verify probe

This PHP function checks if an email address is valid. By default it will only do syntax checking with a regex, but it can also be configured to do a MX record check. I have expanded the function so that it can also be configured to verify the address via an SMTP probe.

It will give an error in these situations:

  • A 5xx SMTP response code is encountered
  • None of the mailservers can be contacted
  • No usable DNS records are found
  • The script take more than a certain amount of time (mostly transient errors)


This function makes connections to remote SMTP servers. This means that outgoing TCP network connections to port 25 must be possible. If this is not the case, then the script will not work.

Some hosting providers block exactly these network connections because they are also used by spammers.
When you always get “None of the mailservers listed for $domain could be contacted”, no matter what address you fill in, this is usually a good indication that port 25 is blocked. In this case there is no workaround other than finding a new hosting provider.

Using this function on a server might cause it’s IP address(es) to get blacklisted. This can be a problem if the server is also a mail server. So don’t use it on a server that runs mail in a production environment.

How to use

Here is a simple example.


  • 15 April 2012 Due to heavy abuse of the simple demo page I had to remove that and add a CAPTCHA to the main page.
  • 21 Februari 2010 My mail server was blacklisted by Microsoft for exhibiting “namespace mining behavior”. Since I already have whitelisted those domains in Postifx, this verification page must have been the cause. I updated the verification code so that it now uses the Postfix access file (currently only type PCRE is supported). If you verify a whitelisted address, the Debug option below will tell you.
  • 30 December 2009 Because on Windows several PHP DNS functions are not available, I have hacked in support via the PEAR Net_DNS class. In order to install Net_DNS however, you need the mhash module in php (lib_mhash.dll). Thanks to for reminding.


  1. thanks for this function which I have been looking for, but the page called email_verify_source shows a blank page so I can’t read this function and I wanted to know if I need to install some other dependancies in addition to this function

  2. hello the link for the script is not working can you give me the script for make bettre than what i had made thanks

  3. This function is really helpful for the email list because I can eliminate the invalid emails from my list. Also the syntax check is very welcomed!

  4. Please note that no file is shown whwn you click on the “This PHP function” link.
    What is downloaded (and not shown by the browser) is:

    Possibly you need to write “<?php" instead of simply "<?"

Leave a comment

Your email address will not be published. Required fields are marked *