When you register on a forum, there is usually an e-mail address verification function. When you enter an illegal format, an error message will appear.
We can use the following regular expression
ereg("^[a-zA-Z0-9_] @[a-zA-Z0-9-] .[a-zA-Z0-9-.] $]", $email);
But the function of the above formula is that it can only check the string and cannot output it. 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 we use PHP to organize the above two functions into 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;
}
}
}
After that, we can use this function to detect whether there is an entered Email, for example:
if(checkEmail(web@etoow.com) == FALSE)
{
echo "The E_mail you entered is incorrect.";
}
else
{
echo "The entered E_mail is correct.";
}