Re: validating email address

From: Date: Thu, 04 Dec 2003 06:33:54 +0000
Subject: Re: validating email address
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-171774@lists.php.net to get a copy of this message
Quick note: The PEAR Validate package does this for you. It also checks for an alternate A record. Terence wrote:
You could use MX records if you wanted to. I found this some time ago... 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;
       }
} } ----- Original Message ----- From: "Blake Schroeder" <blake@lhwd.net> To: <php-general@lists.php.net> Sent: Thursday, December 04, 2003 2:31 AM Subject: [PHP] validating email address Whats the best way to validate email address (check for white space, check for .com, .net.edu etc) -Blake


« previous php.general (#171774) next »