| 域名空间 下载中心 社区论坛 信息公告 my小屋 |
![]() |
联系我们 设为首页 加入收藏 |
|
首页 | 新闻资讯 | 编程开发 | 网页设计 | 图形图象 | 网络媒体 | 网站模板 | 数 据 库 | 投稿 论坛 | 操作系统 | 系统优化 | 网络安全 | 黑客技术 | 硬件学堂 | 硬件报价 | 服 务 器 | 地图 专题 | 应用软件 | 聊天通讯 | q q 专栏 | 建站经验 | 在线工具 | 站长club | 注 册 表 | 旧版 社会 | 游戏娱乐 | 设计欣赏 | 疑难解答 | 社区论坛 | 韩国素材 | 素材图库 | 广告服务 | 服务 |
| 新版上线![旧版] | |||||
注:打开慢时请稍等
精确检查email地址的classhttp://www.iyit.net 日期:2006-10-6 15:34:11 来源:iyit.net收集 点击: |
============================================================================== <? /* * email_validation.php * * @(#) $header: /cvsroot/phplibrary/email_validation.php,v 1.4 1999/11/02 06:19:35 mlemos exp $ * */ class email_validation_class { //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)=="\r\n") return(substr($line,0,$length-2)); } } function putline($connection,$line) { return(fputs($connection,"$line\r\n")); } function validateemailaddress($email) { //return(eregi($this->email_regular_expression,$email)!=0); return(eregi("^([a-z0-9_] ¦\\- ¦\\.)+@(([a-z0-9_] ¦\\-)+\\.)+[a-z]{2,4}$",$email)!=0); } function validateemailhost($email,$hosts=0) { if(!$this->validateemailaddress($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 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(($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); } }; ?> ============================================================================= ----------------------------------------------------------------------------- 应用范例: ============================================================================= echo "<center><br/>检查电子邮件地址的正确性:<br/>"; $newmail = "test@test.com"; require("email_validation.php3"); $validator=new email_validation_class; $validator->timeout=10; if(isset($newemail) && strcmp($newemail,"")) { if(($result=$validator->validateemailbox($newemail))<0) { echo "不能确定您的信箱是否正确. 您的信箱离这里太远了吧?<br/>"; return; } else { if(!$result) { echo "您输入的信箱地址是不正确的! :)<br/>"; return; } else echo "邮箱合法!<br/>"; } } ============================================================================= 编辑:黑鹰 [发送给好友] [打印本页] [关闭窗口] [返回顶部] 上一篇:怎样删除文件夹中含有部分字串的文件? 下一篇:有没有可能一个form同时提交到两个php文件处理? 转载请注明来源:www.iyit.net 特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。 |
| 相关文章 | ||||
| 设置首 页 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接 |
| |||||||