Comprehensive? Y? Email validity

Source: Internet
Author: User
Me ?? Do you often want to worship? Your? Website friends can leave Email & nbsp; but many people are there ?? S, causing management? T's sleepy? _, & Nbsp; following ??? Can the class be? Upper? Z check whether the Email is a valid Email (the Email does not exist) & nbsp; & lt ;? & Nbsp; classCEmail & #123; & nb is generally me ?? Do you often want to worship? Your? Website friends can leave an Email
But many of them ?? S, causing management? T's sleepy? _,
Below ??? Can the class be? Upper? Z. 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 ")


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.