失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 全面測試email的有效性【PHP】

全面測試email的有效性【PHP】

时间:2020-07-12 10:58:27

相关推荐

全面測試email的有效性【PHP】

后端开发|php教程

,效性,全面,connection,if,return,h

后端开发-php教程

一般我們常希望拜訪你的網站的朋友能留下Email

但是很多人都會隨便打,造成管理員的困擾,

以下這個class可以線上檢查Email是否是有效的Email(存不存在)

易语言 网页源码,vscode 设置风格,ubuntu安装图新版,tomcat下载不,sqlite得到所有表,jquery 新闻插件,web前端好看的框架,爬虫page_source,php 中文字,南宁SEO优化方案,赞助网站源码,手机网页底部菜单栏,html5外卖网站模板,js实现悬浮页面,酒店管理系统程序设计,arcgis二次开发的程序独立运行lzw

<?

class CEmail {

var $email_regular_expression=”^([a-z0-9_]|\-|\.) @(([a-z0-9_]|\-) \.) [a-z]{2,4}$”;

var $timeout=0;

var $localhost=””;

var $localuser=””;

114啦网址导航网址源码,vscode图标主题插件,ubuntu 快照命令,tomcat启动报错严重,sqlite3的基本操作,视频网站爬虫系统开发工具,php调用静态函数,永泰企业seo服务电话,网站css图片下载,php集团模板lzw

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)==”rn”)

return(substr($line,0,$length-2));

}

}

搜索按钮网站源码asp,ubuntu 的make命令,沈阳爬虫店招聘,php展示,seo 图片描述lzw

Function PutLine($connection,$line)

{

return(fputs($connection,”$linern”));

}

Function VerifyRule($email)

{

return(eregi($this->email_regular_expression,$email)!=0);

}

Function ValidateEmailHost($email,$hosts=0)

{

if(!$this->VerifyRule($email))

return(0);

$user=strtok($email,”@”);

$domain=strtok(“”);

if(GetMXRR($domain,&$hosts,&$weights))

{

$mxhosts=array();

for($host=0;$host<count($hosts);$host )

$mxhosts[$weights[$host]]=$hosts[$host];

KSort($mxhosts);

for(Reset($mxhosts),$host=0;$host<count($mxhosts);Next($mxhosts),$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 VerifyOnline($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<count($hosts);$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: “)

&& $this->VerifyResultLines($connection,”250″)>0

&& $this->PutLine($connection,”RCPT TO: “)

&& ($result=$this->VerifyResultLines($connection,”250″))>=0)

{

fclose($connection);

return($result);

}

fclose($connection);

}

}

return(-1);

}

function Verify($email,$type=0) {

if($type==0) return $this->VerifyRule($email) ;

elsereturn $this->VerifyOnline($email) ;

}

};

?>

用法:

$m=new CEmail;

//僅檢查語法

if($m->Verify(“jerry@.tw”,0)) echo “有效”;

else echo “無效”;

//線上檢查是否真的有該Email

if($m->Verify(“jerry@.tw”,1)) echo “有效”;

else echo “無效”;

如果觉得《全面測試email的有效性【PHP】》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。