首页 / PHP / php验证信箱是否真实存在
php验证信箱是否真实存在
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php验证信箱是否真实存在,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3677字,纯文字阅读大概需要6分钟。
内容图文
![php验证信箱是否真实存在](/upload/InfoBanner/zyjiaocheng/224/b3c58cfc33eb4f6d9175f3a47a5cf904.jpg)
大家好,我是php新手,现在有个问题想请教大家,就是注册时验证该email地址是否真的存在,谢谢
环境win32+php5.45
test.php
echo "
检查电子邮件地址的正确性:
";
require("email_validation.php");
$newmail = "283285993@qq.com";
$validator=new email_validation_class;
$validator->timeout=10;
//if(IsSet($newemail) && strcmp($newemail,"")){
if( ($result=$validator->ValidateEmailBox($newmail) )<0){
echo "不能确定您的信箱是否正确. 您的信箱离这里太远了吧?
";
return;
}else{
echo "22222222";
if(!$result){
echo "您输入的信箱地址是不正确的! :)
";
return;
}else{
echo "邮箱合法!
";
}
}
?>
email_validation.php
class email_validation_class
{
//var $email_regular_expression="^([a-z0-9_] |//- |//.)+@(([a-z0-9_] |//-)+//.)+[a-z]{2,4}$";
var $timeout=0;
var $localhost="";
var $localuser="";
var $hosts=0;
Function GetLine($connection)
{
for($line="";;)
{
if(feof($connection))
return(0);
$line.=fgets($connection,100);
$length=strlen($line);
if($length>=2 && substr($line,$length-2,2)=="/r/n")
return(substr($line,0,$length-2));
}
}
Function PutLine($connection,$line)
{
return(fputs($connection,"$line/r/n"));
}
Function ValidateEmailAddress($email) {
//return(eregi($this->email_regular_expression,$email)!=0);
//origin:
//return(eregi("^([a-z0-9_] |//- |//.)+@(([a-z0-9_] |//-)+//.)+[a-z]{2,4}$",$email)!=0);
//return preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $_REQUEST[$email]);
return preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $_REQUEST[$email]);
}
Function ValidateEmailHost($email,$hosts=0)
{
if(!$this->ValidateEmailAddress($email))
return(0);
$user=strtok($email,"@");
$domain=strtok("");
if(GetMXRR($domain,$hosts,$weights))
{
$mxhosts=array();
for($host=0;$host$mxhosts[$weights[$host]]=$hosts[$host];
KSort($mxhosts);
for(Reset($mxhosts),$host=0;$host$hosts[$host]=$mxhosts[Key($mxhosts)];
}
else
{
$hosts=array();
if(strcmp(@gethostbyname($domain),$domain)!=0)
$hosts[]=$domain;
}
return(count($hosts)!=0);
}
Function VerifyResultLines($connection,$code)
{
while(($line=$this->GetLine($connection)))
{
if(!strcmp(strtok($line," "),$code))
return(1);
if(strcmp(strtok($line,"-"),$code))
return(0);
}
return(-1);
}
Function ValidateEmailBox($email)
{
if(!$this->ValidateEmailHost($email,$hosts))
return(0);
if(!strcmp($localhost=$this->localhost,"") && !strcmp($localhost=getenv("SERVER_NAME"),"") && !strcmp($localhost=getenv("HOST"),""))
$localhost="localhost";
if(!strcmp($localuser=$this->localuser,"") && !strcmp($localuser=getenv("USERNAME"),"") && !strcmp($localuser=getenv("USER"),""))
$localuser="root";
for($host=0;$host{
if(($connection=($this->timeout ? fsockopen($hosts[$host],25,$errno,$error,$this->timeout) : fsockopen($hosts[$host],25))))
{
if($this->VerifyResultLines($connection,"220")>0 && $this->PutLine($connection,"HELO $localhost") && $this->VerifyResultLines($connection,"250")>0 && $this->PutLine($connection,"MAIL FROM: <$localuser@$localhost>") && $this->VerifyResultLines($connection,"250")>0 && $this->PutLine($connection,"RCPT TO: <$email>") && ($result=$this->VerifyResultLines($connection,"250"))>=0)
{
fclose($connection);
return($result);
}
fclose($connection);
}
}
return(-1);
}
};
?>
分享到:
------解决方案--------------------
不懂,我的想法就是,最多验证一下格式是否正确,然后像大家一样,往他邮箱发激活码,用以完成注册的最后一步。你想要直接验证,除非邮箱服务商提供接口让你验证。不然。
------解决方案--------------------
email 的真实性是无法判断的,虽然任何一个邮件服务器都有邮箱列表功能。但大多都不会对外开放
需要用邮件激活注册,看上去不错。但是建立在网站管理员的职业道德上的。你收到的那些广告邮件就是这样来的
内容总结
以上是互联网集市为您收集整理的php验证信箱是否真实存在全部内容,希望文章能够帮你解决php验证信箱是否真实存在所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。