Re: Email Verification
| From: | Al | Date: | Wed, 17 Sep 2008 13:59:39 +0000 |
| Subject: | Re: Email Verification | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-280360@lists.php.net to get a copy of this message | ||
Tom Chubb wrote:
Can anyone offer advice on best practices for email address verification? Obviously for user registration it's common to click a link in your email to complete the process thereby verifying the email, but if you want to keep things very simple for the end user, what are the best methods? I have been looking at getmxrr and the examples feature some good advice, etc. One that I've found that I'm thinking of using is http://www.tienhuis.nl/php-email-address-validation-with-verify-probe which tries to connect to the SMTP server as well as mx lookup, etc. How reliable are these? With new domain name extensions appearing all the time I wanted to find something better than a regex which might become outdated after a while and I'd never know about it! Thoughts please and thanks in advanceHere's what I use. It's simple, uses php5 functions and appears to catch most obvious user input errors. function checkEmailAddr($emailAddr) {
if(!filter_var($emailAddr, FILTER_VALIDATE_EMAIL)) throw new Exception("Email address error. Syntax is wrong.");
$domain = substr(strchr($emailAddr, '@'), 1);
if(!checkdnsrr($domain))
{
throw new Exception("Email address warning. Specified domain \"$domain\" appears to be invalid. Check carefully.");
}
return true;
}
Use in try/catch code, e.g.,
try
{
$emailAddrOK = checkEmailAddr($userSubmitedDataArray[EMAIL_ADDR_FIELD]);
}
catch (Exception $e)
{
$errorMsg = $e->getMessage(); //Message text in check function
$emailAddrOK= false;
}