php的简单SMTP电子邮件验证功能?还有,值得吗?

chr*_*ris 5 php email

有没有人能够通过PHP在PHP中验证电子邮件地址?还有,值得吗?它会降低我的服务器速度吗?

- >编辑:我指的是这样的:

http://onwebdevelopment.blogspot.com/2008/08/php-email-address-validation-through.html

这是为了补充电子邮件地址语法的验证.

虽然看起来很复杂,但我希望有一种更简单的方法.

kar*_*m79 4

如果您想检查域中是否有邮件交换器,您可以使用如下命令:

/*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;
}
Run Code Online (Sandbox Code Playgroud)

用法:

$validated = checkEmail('foo@gmail.com', true);
Run Code Online (Sandbox Code Playgroud)