欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

全面測試email的有效性_PHP教程

程序员文章站 2023-12-28 17:27:52
...
一般我們常希望拜訪你的網站的朋友能留下Email
但是很多人都會隨便打,造成管理員的困擾,
以下這個class可以線上檢查Email是否是有效的Email(存不存在)


class CEmail {
var $email_regular_expression="^([a-z0-9_]|-|.)+@(([a-z0-9_]|-)+.)+[a-z]{2,4}$";
var $timeout=0;
var $localhost="";
var $localuser="";

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));
}
}

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$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 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{
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")

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/509063.htmlTechArticle一般我們常希望拜訪你的網站的朋友能留下Email 但是很多人都會隨便打,造成管理員的困擾, 以下這個class可以線上檢查Email是否是有效的Ema...

上一篇:

下一篇: