php应验邮箱是否真实存在

php中文网
发布: 2016-06-13 10:44:39
原创
1230人浏览过

php验证邮箱是否真实存在
大家好,我是php新手,现在有个问题想请教大家,就是注册时验证该email地址是否真的存在,谢谢 

环境win32+php5.45

test.php

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpecho "<center><br/>检查电子邮件地址的正确性:<br/>"; require("email_validation.php"); $newmail = "[email&#160;protected]"; $validator=new email_validation_class; $validator->timeout=10; //if(IsSet($newemail) && strcmp($newemail,"")){    if( ($result=$validator->ValidateEmailBox($newmail) )<0){         echo "不能确定您的信箱是否正确. 您的信箱离这里太远了吧?<br/>";         return;     }else{             echo "22222222";        if(!$result){             echo "您输入的信箱地址是不正确的! :)<br/>";             return;         }else{            echo "邮箱合法!<br/>";         }     }?>
登录后复制



email_validation.php

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 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=""; var $hosts=0;Function GetLine($connection) { for($line="";;) { if(feof($connection)) return(0); $line.=fgets($connection,100); $length=strlen($line); if($length&gt;=2 &amp;&amp; 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-&gt;email_regular_expression,$email)!=0); //origin://return(eregi("^([a-z0-9_] |//- |//.)+@(([a-z0-9_] |//-)+//.)+[a-z]{2,4}$",$email)!=0); //return preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $_REQUEST[$email]);return preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $_REQUEST[$email]);} Function ValidateEmailHost($email,$hosts=0) { if(!$this-&gt;ValidateEmailAddress($email)) return(0); $user=strtok($email,"@"); $domain=strtok(""); if(GetMXRR($domain,$hosts,$weights)) { $mxhosts=array(); for($host=0;$host<count ksort for else if return function verifyresultlines while>GetLine($connection))) { if(!strcmp(strtok($line," "),$code)) return(1); if(strcmp(strtok($line,"-"),$code)) return(0); } return(-1); } Function ValidateEmailBox($email) { if(!$this-&gt;ValidateEmailHost($email,$hosts)) return(0); if(!strcmp($localhost=$this-&gt;localhost,"") &amp;&amp; !strcmp($localhost=getenv("SERVER_NAME"),"") &amp;&amp; !strcmp($localhost=getenv("HOST"),"")) $localhost="localhost"; if(!strcmp($localuser=$this-&gt;localuser,"") &amp;&amp; !strcmp($localuser=getenv("USERNAME"),"") &amp;&amp; !strcmp($localuser=getenv("USER"),"")) $localuser="root"; for($host=0;$host<count if>timeout ? fsockopen($hosts[$host],25,$errno,$error,$this-&gt;timeout) : fsockopen($hosts[$host],25)))) { if($this-&gt;VerifyResultLines($connection,"220")&gt;0 &amp;&amp; $this-&gt;PutLine($connection,"HELO $localhost") &amp;&amp; $this-&gt;VerifyResultLines($connection,"250")&gt;0 &amp;&amp; $this-&gt;PutLine($connection,"MAIL FROM: ") &amp;&amp; $this-&gt;VerifyResultLines($connection,"250")&gt;0 &amp;&amp; $this-&gt;PutLine($connection,"RCPT TO: ") &amp;&amp; ($result=$this-&gt;VerifyResultLines($connection,"250"))&gt;=0) { fclose($connection); return($result); } fclose($connection); } } return(-1); } }; ?&gt;<div class="clear"></div></count></count>
登录后复制
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号