检查电子邮件是否存在 php [英] Check if email exist php

查看:33
本文介绍了检查电子邮件是否存在 php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我有一个 php 脚本来检查电子邮件地址是否存在.

I have a question, i have a php script to check if the email address exist.

但似乎 yahoo、hotmail、aol 和其他提供商正在接受任何电子邮件,而不是拒绝无效电子邮件.

But appear that yahoo, hotmail, aol and others providers are accepting any emails and not rejecting the invalid emails.

只有 Gmail 和许多域(如 stackoverflow.com)拒绝无效电子邮件.

Only Gmail, and many domains like stackoverflow.com are rejecting the no vaild emails.

检查我的脚本,让我知道我是否可以做一些检查雅虎和其他人的事情.

Check my script and let me know if i can do some to check the yahoo and others.

html 帖子表单

<html>
<body>
<form action="checkemail.php" method="POST">
<b>E-mail</b> <input type="text" name="email">
<input type="submit">
</form>
</body>
</html>

php

<?php

/* Validate an email address. */
function jValidateEmailUsingSMTP($sToEmail, $sFromDomain = "gmail.com", $sFromEmail = "email@gmail.com", $bIsDebug = false) {

    $bIsValid = true; // assume the address is valid by default..
    $aEmailParts = explode("@", $sToEmail); // extract the user/domain..
    getmxrr($aEmailParts[1], $aMatches); // get the mx records..

    if (sizeof($aMatches) == 0) {
        return false; // no mx records..
    }

    foreach ($aMatches as $oValue) {

        if ($bIsValid && !isset($sResponseCode)) {

            // open the connection..
            $oConnection = @fsockopen($oValue, 25, $errno, $errstr, 30);
            $oResponse = @fgets($oConnection);

            if (!$oConnection) {

                $aConnectionLog['Connection'] = "ERROR";
                $aConnectionLog['ConnectionResponse'] = $errstr;
                $bIsValid = false; // unable to connect..

            } else {

                $aConnectionLog['Connection'] = "SUCCESS";
                $aConnectionLog['ConnectionResponse'] = $errstr;
                $bIsValid = true; // so far so good..

            }

            if (!$bIsValid) {

                if ($bIsDebug) print_r($aConnectionLog);
                return false;

            }

            // say hello to the server..
            fputs($oConnection, "HELO $sFromDomain
");
            $oResponse = fgets($oConnection);
            $aConnectionLog['HELO'] = $oResponse;

            // send the email from..
            fputs($oConnection, "MAIL FROM: <$sFromEmail>
");
            $oResponse = fgets($oConnection);
            $aConnectionLog['MailFromResponse'] = $oResponse;

            // send the email to..
            fputs($oConnection, "RCPT TO: <$sToEmail>
");
            $oResponse = fgets($oConnection);
            $aConnectionLog['MailToResponse'] = $oResponse;

            // get the response code..
            $sResponseCode = substr($aConnectionLog['MailToResponse'], 0, 3);
            $sBaseResponseCode = substr($sResponseCode, 0, 1);

            // say goodbye..
            fputs($oConnection,"QUIT
");
            $oResponse = fgets($oConnection);

            // get the quit code and response..
            $aConnectionLog['QuitResponse'] = $oResponse;
            $aConnectionLog['QuitCode'] = substr($oResponse, 0, 3);

            if ($sBaseResponseCode == "5") {
                $bIsValid = false; // the address is not valid..
            }

            // close the connection..
            @fclose($oConnection);

        }

    }

    if ($bIsDebug) {
        print_r($aConnectionLog); // output debug info..
    }

    return $bIsValid;

}
$email = $_POST['email'];

$bIsEmailValid = jValidateEmailUsingSMTP("$email", "gmail.com", "email@gmail.com");
echo $bIsEmailValid ? "<b>Valid!</b>" : "Invalid! :(";
?>

推荐答案

如果您需要确保电子邮件地址存在,请向其发送电子邮件.它应该包含一个带有随机 ID 的链接.只有当该链接被点击并且包含正确的随机 ID 时,用户的帐户才会被激活(或发布广告、发送订单或您正在执行的任何操作).

If you need to make super sure that an E-Mail address exists, send an E-Mail to it. It should contain a link with a random ID. Only when that link is clicked, and contains the correct random ID, the user's account is activated (or ad published, or order sent, or whatever it is that you are doing).

这是验证电子邮件地址存在的唯一可靠方法,并确保填写表格的人可以访问它.

This is the only reliable way to verify the existence of an E-Mail address, and to make sure that the person filling in the form has access to it.

这篇关于检查电子邮件是否存在 php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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