如何使用PHP检查电子邮件地址是否真实或有效 [英] How to check if an email address is real or valid using PHP

查看:258
本文介绍了如何使用PHP检查电子邮件地址是否真实或有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以检查电子邮件是否存在与本网站相似?

http://verify-email.org/

<?php
    if($_POST['email'] != ''){
        // The email to validate
        $email = $_POST['email'];

        // An optional sender
        function domain_exists($email, $record = 'MX'){
            list($user, $domain) = explode('@', $email);
            return checkdnsrr($domain, $record);
        }
        if(domain_exists($email)) {
            echo('This MX records exists; I will accept this email as valid.');
        }
        else {
            echo('No MX record exists;  Invalid email.');
        }
    }
?>
<form method="POST">
    <input type="text" name="email">
    <input type="submit" value="submit">
</form>

这是我现在所在的。 它检查域是否存在,但不能检查
用户的电子邮件是否存在于该域
。您可以使用PHP进行此操作吗?

This is what I have right now. It checks if the domain exist, but it cannot check if the user's email exist on that domain. Is it possible to do that using PHP?

推荐答案

您应该使用SMTP进行检查。

You should check with SMTP.

这意味着您必须连接到该电子邮件的SMTP服务器。

That means you have to connect to that email's SMTP server.

连接到SMTP服务器后,您应发送以下命令:

After connecting to the SMTP server you should send these commands:

HELO somehostname.com
MAIL FROM: <no-reply@gmail.com>
RCPT TO: <emailtovalidate@domain.com>

如果您获得< emailtovalidate@domain.com>:中继访问被拒绝,这意味着此电子邮件无效。

If you get "<emailtovalidate@domain.com>: Relay access denied" that means this email in invalid.

有一个简单的PHP类。您可以使用它:

There is a simple PHP class. You can use it:

http://www.phpclasses.org/package/6650-PHP-Check-if-an-e-mail-is-valid-using- SMTP.html

这篇关于如何使用PHP检查电子邮件地址是否真实或有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆