一般我們常希望拜訪你的網站的朋友能留下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)
http://www.bkjia.com/phpjc/509063.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/509063.htmltecharticle一般我們常希望拜訪你的網站的朋友能留下email 但是很多人都會隨便打,造成管理員的困擾, 以下這個class可以線上檢查email是否是有效的ema...