以下代码可以!<?
class CEmail {
//var $email_regular_expression="^([a-z0-9_]|-|.)+@(([a-z0-9_]|-)+.)+[a-z]{2,4}$";
//var $email_regular_expression="^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$";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<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: <$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);
} function Verify($email,$type=0)
{
if($type==0) return $this->VerifyRule($email) ;
else return $this->VerifyOnline($email) ; } }if($ocp)
{
//用法:
$m=new CEmail;
//僅檢查語法
//if($m->Verify("[email protected]",0)) echo "有效";
//else echo "無效"; //線上檢查是否真的有該Email
if($m->Verify("$ocp",1)) echo "有效";
else echo " $ocp 無效";
}
else
{
echo
"
<form method=POST action=$PHP_SELF>
<p>
<input type=text name=ocp size=20>
<input type=submit value=提交 name=B1>
</p>
</form>
";
}
?>
class CEmail {
//var $email_regular_expression="^([a-z0-9_]|-|.)+@(([a-z0-9_]|-)+.)+[a-z]{2,4}$";
//var $email_regular_expression="^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3}$";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<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: <$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);
} function Verify($email,$type=0)
{
if($type==0) return $this->VerifyRule($email) ;
else return $this->VerifyOnline($email) ; } }if($ocp)
{
//用法:
$m=new CEmail;
//僅檢查語法
//if($m->Verify("[email protected]",0)) echo "有效";
//else echo "無效"; //線上檢查是否真的有該Email
if($m->Verify("$ocp",1)) echo "有效";
else echo " $ocp 無效";
}
else
{
echo
"
<form method=POST action=$PHP_SELF>
<p>
<input type=text name=ocp size=20>
<input type=submit value=提交 name=B1>
</p>
</form>
";
}
?>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货