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)
Updates
2010-02-21 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.
2009-12-30 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 webdesign.berend@planet.nl for reminding.
Simple demo
I have put a simple demo online (sourcecode here).
Fancy demo
Using HTML_QuickForm I have put a demo version below, so feel free to try it out: