<?
/*
* email_validation.php
*
* @(#) $Header: /home/mlemos/cvsroot/PHPlibrary/email_validation.php,v 1.16 2002/08/12 04:28:37 mlemos Exp $
*
*/
class email_validation_class
{
var $email_regular_expression="^([-!#\$%&'*+./0-9=?A-Z^_`a-z{|}~])+@([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,6}\$";
var $timeout=0;
var $localhost="";
var $localuser="";
var $debug=0;
var $html_debug=0;
var $exclude_address="";
var $getmxrr="GetMXRR";
var $next_token="";
Function Tokenize($string,$separator="")
{
if(!strcmp($separator,""))
{
$separator=$string;
$string=$this->next_token;
}
for($character=0;$character<strlen($separator);$character++)
{
if(GetType($position=strpos($string,$separator[$character]))=="integer")
$found=(IsSet($found) ? min($found,$position) : $position);
}
if(IsSet($found))
{
$this->next_token=substr($string,$found+1);
return(substr($string,0,$found));
}
else
{
$this->next_token="";
return($string);
}
}
Function OutputDebug($message)
{
$message.="\n";
if($this->html_debug)
$message=str_replace("\n","<br />\n",HtmlEntities($message));
echo $message;
flush();
}
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")
{
$line=substr($line,0,$length-2);
if($this->debug)
$this->OutputDebug("S $line");
return($line);
}
}
}
Function PutLine($connection,$line)
{
if($this->debug)
$this->OutputDebug("C $line");
return(fputs($connection,"$line\r\n"));
}
Function ValidateEmailAddress($email)
{
return(eregi($this->email_regular_expression,$email)!=0);
}
Function ValidateEmailHost($email,&$hosts)
{
if(!$this->ValidateEmailAddress($email))
return(0);
$user=$this->Tokenize($email,"@");
$domain=$this->Tokenize("");
$hosts=array();
$getmxrr=$this->getmxrr;
if(function_exists($getmxrr)
&& $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
{
if(strcmp($ip=@gethostbyname($domain),$domain)
&& (strlen($this->exclude_address)==0
|| strcmp(@gethostbyname($this->exclude_address),$ip)))
$hosts[]=$domain;
}
return(count($hosts)!=0);
}
Function VerifyResultLines($connection,$code)
{
while(($line=$this->GetLine($connection)))
{
if(!strcmp($this->Tokenize($line," "),$code))
return(1);
if(strcmp($this->Tokenize($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<count($hosts);$host++)
{
if($this->debug)
$this->OutputDebug("Resolving host name \"".$hosts[$host]."\"...");
$domain=$hosts[$host];
if(!strcmp($ip=@gethostbyname($domain),$domain))
{
$this->OutputDebug("Could not resolve host name \"".$hosts[$host]."\".");
continue;
}
if(strlen($this->exclude_address)
&& !strcmp(@gethostbyname($this->exclude_address),$ip))
{
$this->OutputDebug("Host address of \"".$hosts[$host]."\" is the exclude address");
continue;
}
if($this->debug)
$this->OutputDebug("Connecting to host address \"".$ip."\"...");
if(($connection=($this->timeout ? @fsockopen($ip,25,$errno,$error,$this->timeout) : @fsockopen($ip,25))))
{
if($this->debug)
$this->OutputDebug("Connected.");
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)
{
if($this->debug)
$this->OutputDebug("This host states that the address is ".($result ? "" : "not ")."valid.");
fclose($connection);
if($this->debug)
$this->OutputDebug("Disconnected.");
return($result);
}
if($this->debug)
$this->OutputDebug("Unable to validate the address with this host.");
fclose($connection);
if($this->debug)
$this->OutputDebug("Disconnected.");
}
else
{
if($this->debug)
$this->OutputDebug("Failed.");
}
}
return(-1);
}
};
?>
没有合适的资源?快使用搜索试试~ 我知道了~
Emailvalidation
共3个文件
php:2个
html:1个
需积分: 50 27 下载量 77 浏览量
2004-08-02
16:25:30
上传
评论
收藏 5KB ZIP 举报
温馨提示
Emailvalidation Class that may be used to determine if a given e-mail address is valid. It features: - Simple validation just by looking at the e-mail address string. - Validation of a e-mail address host as a valid mail exchange domain. - Validation of a e-mail address by connecting to the mail host server to determine if there is really a deliverable mail box. - Works under Windows or other platforms that do not have the GetMXRR function enabled, using Moriyoshi Koizumi DNS resolver class.
资源推荐
资源详情
资源评论
收起资源包目录
20040802042906.zip (3个子文件)
getmxrr.php 4KB
test_email_validation.html 4KB
email_validation.php 5KB
共 3 条
- 1
资源评论
ljs2002
- 粉丝: 2
- 资源: 262
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功