如何使用PHP检查电子邮件地址是否真实或有效

如何使用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