When you register on a forum, there is usually an e-mail address verification function. When you enter an invalid format, an error message will appear.
We can use the following rule expression
Ereg ("^ [a-zA-Z0-9 _] @ [a-zA-Z0-9-]. [a-zA-Z0-9-.] $]", $ email );
However, the sub-function above only checks strings and does not support output. We can further use this formula to achieve the function of returning information:
If (eregi ("^ [a-zA-Z0-9 _] @ [a-zA-Z0-9-]. [a-zA-Z0-9-.] $]", $ email ))
{
Return FALSE;
}
Next we can further check whether the host name exists:
List ($ Username, $ Domain) = split ("@", $ email );
If (getmxrr ($ Domain, $ MXHost ))
{
Return TRUE;
}
Else
{
If (fsockopen ($ Domain, 25, $ errno, $ errstr, 30 ))
{
Return TRUE;
}
Else
{
Return FALSE;
}
}
Now Let's organize the above two functions with PHP to form a function:
Function checkEmail ($ email)
{If (eregi ("^ [a-zA-Z0-9 _] @ [a-zA-Z0-9-]. [a-zA-Z0-9-.] $]", $ email ))
{
Return FALSE;
}
List ($ Username, $ Domain) = split ("@", $ email );
If (getmxrr ($ Domain, $ MXHost ))
{
Return TRUE;
}
Else
{
If (fsockopen ($ Domain, 25, $ errno, $ errstr, 30 ))
{
Return TRUE;
}
Else
{
Return FALSE;
}
}
}
Then we can use this function to check whether an input Email exists. For example:
If (checkEmail (web@etoow.com) = FALSE)
{
Echo "The E_mail you entered is incorrect .";
}
Else
{
Echo "the input E_mail is correct .";
}