Page 3 of 3
Using the function
To make everything fit together the complete function is:
function validateEmail($email){ list($name,$Domain) = split('@',$email); $result=getmxrr($Domain,$POFFS); if(!$result){$POFFS[0]=$Domain;} $timeout=5; $oldErrorLevel= error_reporting(!E_WARNING); $result=false; foreach($POFFS as $PO ) { $sock = fsockopen($PO, 25, $errno, $errstr, $timeout); if($sock){ fwrite($sock, "HELO Mydomain.com\n"); $response= getResponse($sock); fwrite($sock, "MAIL FROM: <me@mydomain.com>\n"); $response= getResponse($sock); fwrite($sock,"RCPT TO: <".$email.">\n"); $response= getResponse($sock); list($code,$msg)=explode(' ',$response); fwrite($sock,"RSET\n"); $response= getResponse($sock); fwrite($sock,"quit\n"); fclose($sock); if ($code == '250') { $result= true; break; } } } error_reporting($oldErrorLevel); return $result; }
To use the function you simply write something like:
if( validateEmail("name@domain")){ echo "valid"; }else{ echo "not valid"; }
There is a small possibility that if you use this sort of validation too often at any given site then you might be blacklisted, but as long as the frequency is low enough not to annoy it should be fine.
To access the code for this project, once you have registered, click on CodeBin.
If you would like to be informed about new articles on I Programmer you can either follow us on Twitter, on Facebook or you can subscribe to our weekly newsletter.
Disk Drive Dangers - SMART and WMI
Getting access from an application to the hardware is never easy. If you want to know how well your disk drive is performing then there is a way of accessing the SMART data - including the temper [ ... ]
|
AWS Low Cost Mailing List Using phpList And SES
Running a mailing list is not easy or cheap, but if you use AWS it can be. Find out how to create a low-cost and highly effective mailing list server.
| Other Projects |
|