php - 用于 php 的简单 SMTP 电子邮件验证功能?另外,值得吗?

标签 php email

有没有人有在 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/

相关文章:

php - URL 重写和 robots.txt

PHP:替换utf-8字符串中的无效字符

php - 任务(父)和任务实例(子): choose 1 image out of 6 with PHP and MySQL?

php - 如何通过一个输入从两个不同的表中获取结果

php - 从同一个表中过滤逗号分隔值

html - 在浏览器中查看电子邮件并转发给 friend

ios - 使用 mailTo 将多个电子邮件地址发送到邮件应用程序

c# - .Net smtp 不发送电子邮件,没有错误

html - ColdFusion If 语句导致 <cfmail> 中出现空格

php - 更专业的错误处理