有没有人有在 PHP 中通过 SMTP 验证电子邮件地址的好函数? 另外,值得吗?它会降低我的服务器速度吗?
--> 编辑:我指的是这样的:
http://onwebdevelopment.blogspot.com/2008/08/php-email-address-validation-through.html
这是为了补充电子邮件地址语法的验证。
虽然看起来很复杂,但我希望有一种更简单的方法。
最佳答案
如果你想检查域中是否有邮件交换器,你可以使用这样的东西:
/*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 - 用于 php 的简单 SMTP 电子邮件验证功能?另外,值得吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/931725/