In general, we often hope that friends on your website can leave an Email, but many users may leave it as soon as possible, causing difficulties for administrators, the following class can be used to check whether the Email is valid (the Email does not exist) & lt ;? ClassCEmail {var $ email_regular_exPRession & quot; ^ ([a-z0-9 _] |-| .) + @ ([a-z0-9 _ we often hope that friends of your website can leave an Email
However, many users will fight immediately, causing difficulties for administrators,
The following class can be used to check whether the Email is valid (the Email does not exist)
Class CEmail {
Var $ email_regular_exPRession = "^ ([a-z0-9 _] | \-| \.) + @ ([a-z0-9 _] | \-) + \.) + [a-z] {2, 4} $ ";
Var $ timeout = 0;
Var $ localhost = "";
Var $ localuser = "";
Function GetLine ($ connection)
{
For ($ line = "";;)
{
If (feof ($ connection ))
Return (0 );
$ Line. = fgets ($ connection, 100 );
$ Length = strlen ($ line );
If ($ length> = 2
& Substr ($ line, $ length-2, 2) = "rn ")
Return (substr ($ line, 0, $ length-2 ));
}
}
Function PutLine ($ connection, $ line)
{
Return (fputs ($ connection, "$ linern "));
}
Function VerifyRule ($ email)
{
Return (eregi ($ this-> email_regular_expression, $ email )! = 0 );
}
Function ValidateEmailHost ($ email, $ hosts = 0)
{
If (! $ This-> VerifyRule ($ email ))
Return (0 );
$ User = strtok ($ email ,"@");
$ Domain = strtok ("");
If (GetMXRR ($ domain, & $ hosts, & $ weights ))
{
$ Mxhosts = array ();
For ($ host = 0; $ host $ Mxhosts [$ weights [$ host] = $ hosts [$ host];
KSort ($ mxhosts );
For (Reset ($ mxhosts), $ host = 0; $ host $ Hosts [$ host] = $ mxhosts [Key ($ mxhosts)];
}
Else
{
$ Hosts = array ();
If (strcmp (@ gethostbyname ($ domain), $ domain )! = 0)
$ Hosts [] = $ domain;
}
Return (count ($ hosts )! = 0 );
}
Function VerifyResultLines ($ connection, $ code)
{
While ($ line = $ this-> GetLine ($ connection )))
{
If (! Strcmp (strtok ($ line, ""), $ code ))
Return (1 );
If (strcmp (strtok ($ line, "-"), $ code ))
Return (0 );
}
Return (-1 );
}
Function VerifyOnline ($ email)
{
If (! $ This-> ValidateEmailHost ($ email, & $ hosts ))
Return (0 );
If (! Strcmp ($ localhost = $ this-> localhost ,"")
&&! Strcmp ($ localhost = getenv ("SERVER_NAME "),"")
&&! Strcmp ($ localhost = getenv ("HOST "),""))
$ Localhost = "localhost ";
If (! Strcmp ($ localuser = $ this-> localuser ,"")
&&! Strcmp ($ localuser = getenv ("USERNAME "),"")
&&! Strcmp ($ localuser = getenv ("USER "),""))
$ Localuser = "root ";
For ($ host = 0; $ host {
If ($ connection = ($ this-> timeout? Fsockopen ($ hosts [$ host], 25, & $ errno, & $ error, $ this-> timeout): fsockopen ($ hosts [$ host], 25 ))))
{
If ($ this-> VerifyResultLines ($ connection, "220")> 0
& $ This-> PutLine ($ connection, "HELO $ localhost ")
& $ This-> VerifyResultLines ($ connection, "250")> 0
& $ This-> PutLine ($ connection, "mail from: <$ localuser @ $ localhost> ")
& $ This-> VerifyResultLines ($ connection, "250")> 0
& $ This-> PutLine ($ connection, "rcpt to: <$ email> ")
& ($ Result = $ this-> VerifyResultLines ($ connection, "250")> = 0)
{
Fclose ($ connection );
Return ($ result );
}
Fclose ($ connection );
}
}
Return (-1 );
}
Function Verify ($ email, $ type = 0 ){
If ($ type = 0) return $ this-> VerifyRule ($ email );
Else return $ this-> VerifyOnline ($ email );
}
};
?>
Usage:
$ M = new CEmail;
// Checking the checking method
If ($ m-> Verify ("jerry@mail.jerry.com.tw", 0) echo "valid ";
Else echo "ineffective ";
// Check whether there is an Email on the token
If ($ m-> Verify ("jerry@mail.jerry.com.tw", 1) echo "valid ";
Else echo "ineffective ";