When you register on a forum, there is usually an e-mail address verification function, when you enter an illegal format, there will be some kind of error message.
We can use the following rule expression
Ereg ("^[a-za-z0-9_] @[a-za-z0-9-]. [ a-za-z0-9-.] $] ", $email);
But the function of the above equation is to check only strings and not 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;
}
Here we can go further to detect the host name, does it exist:
List ($Username, $Domain) = Split ("@", $email);
if (GETMXRR ($Domain, $MXHost))
{
return TRUE;
}
Else
{
if (Fsockopen ($Domain, $errno, $errstr, 30))
{
return TRUE;
}
Else
{
return FALSE;
}
}
Now we'll organize the top two features in 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, $errno, $errstr, 30))
{
return TRUE;
}
Else
{
return FALSE;
}
}
}
We can then use this function to detect the existence of an incoming email, for example:
if (Checkemail (web@etoow.com) = = FALSE)
{
echo "The E_Mail you entered is not correct.";
}
Else
{
echo "The input e_mail is correct."
}