note 34133 deleted from function.ereg by irchtml
| From: | irchtml@php.net | Date: | Wed, 25 Feb 2004 17:31:25 +0000 |
| Subject: | note 34133 deleted from function.ereg by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65744@lists.php.net to get a copy of this message | ||
Note Submitter: cwilliams@aerospace.state.al.us
----
I found this to be the most efficient way of validating email addresses. I have scoured the
internet looking for code and found some and made it a little simpler and it has 0 false positives.
//@Author: Chris Williams
//@Date: 7/16/03
//@Description: This function takes a scalar value as an argument then
// it validates it with a reg exp then sees if the domain exists
//@Usage: if(checkEmail($var))... ;
function checkEmail($Email) {
//Do the basic Reg Exp Matching for simple validation
if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $Email)) {
return FALSE;
}
//split the Email Up for Server validation
list($Username, $Domain) = split("@",$Email);
//If you get an mx record then this is a valid email domain
if(getmxrr($Domain, $MXHost)) {
return TRUE;
}
else {
//else use the domain given to try and connect on port 25
//if you can connect then it's a valid domain and that's good enough
if(fsockopen($Domain, 25, $errno, $errstr, 30)) {
return TRUE;
}
else {
return FALSE;
}
}
}