检查电子邮件是否存在php
发布时间:2020-12-13 22:22:50 所属栏目:PHP教程 来源:网络整理
导读:我有一个问题,我有一个 PHP脚本来检查电子邮件地址是否存在. 但似乎雅虎,hotmail,aol和其他提供商正在接受任何电子邮件,而不是拒绝无效的电子邮件. 只有Gmail和许多像stackoverflow.com这样的域名都拒绝了没有虚假的电子邮件. 检查我的脚本,让我知道我是否可
我有一个问题,我有一个
PHP脚本来检查电子邮件地址是否存在.
但似乎雅虎,hotmail,aol和其他提供商正在接受任何电子邮件,而不是拒绝无效的电子邮件. 只有Gmail和许多像stackoverflow.com这样的域名都拒绝了没有虚假的电子邮件. 检查我的脚本,让我知道我是否可以做一些检查雅虎和其他人. 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 $sFromDomainrn"); $oResponse = fgets($oConnection); $aConnectionLog['HELO'] = $oResponse; // send the email from.. fputs($oConnection,"MAIL FROM: <$sFromEmail>rn"); $oResponse = fgets($oConnection); $aConnectionLog['MailFromResponse'] = $oResponse; // send the email to.. fputs($oConnection,"RCPT TO: <$sToEmail>rn"); $oResponse = fgets($oConnection); $aConnectionLog['MailToResponse'] = $oResponse; // get the response code.. $sResponseCode = substr($aConnectionLog['MailToResponse'],3); $sBaseResponseCode = substr($sResponseCode,1); // say goodbye.. fputs($oConnection,"QUITrn"); $oResponse = fgets($oConnection); // get the quit code and response.. $aConnectionLog['QuitResponse'] = $oResponse; $aConnectionLog['QuitCode'] = substr($oResponse,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时,才会激活用户的帐户(或广告发布,或发送订单,或者您正在执行的任何操作).
这是验证电子邮件地址是否存在的唯一可靠方法,并确保填写表单的人员可以访问它. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |