PHP的简单SMTP电子邮件验证功能?另外,值得吗? [英] Simple SMTP email validation function for php? Also, is it worth it?
本文介绍了PHP的简单SMTP电子邮件验证功能?另外,值得吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人在PHP中通过SMTP验证电子邮件地址是否具有良好的功能?另外,值得吗?会减慢我的服务器速度吗?
Does anybody have a good function for validating email addresses by SMTP in PHP? Also, is it worth it? Will it slow down my server?
->我指的是这样的东西:
--> I am referring to something like this:
http://onwebdevelopment.blogspot.com/2008/08/php-email-address-validation-through.html
这是对电子邮件地址语法验证的补充.
which is meant to complement validation of the syntax of the email address.
虽然看起来很复杂,但我希望有一种更简单的方法.
It looks complicated though, and I was hoping there was a simpler way of doing this.
推荐答案
如果您要检查域中是否存在邮件交换器,可以使用以下命令:
If you want to check if there is a mail exchanger at the domain, you can use something like this:
/*checks if email is well formed and optionally the existence of a MX at that domain*/
function checkEmail($email, $domainCheck = false)
{
if (preg_match('/^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\-\.]+'.
'\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $email)) {
if ($domainCheck && function_exists('checkdnsrr')) {
list (, $domain) = explode('@', $email);
if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) {
return true;
}
return false;
}
return true;
}
return false;
}
用法:
$validated = checkEmail('foo@gmail.com', true);
这篇关于PHP的简单SMTP电子邮件验证功能?另外,值得吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文