用PHP验证邮箱有效性
2010-06-21 17:57
405 查看
在sitepoint挖到一篇Verify a User’s Email Address Using PHP,本来打算自己翻译一下,学习一下。所以翻PHP Funtion查找当中出现的函数,无意中就发现checkdnsrr函数那里就有了更精妙的例子,分享给大家!
注意:checkdnsrr函数在win主机上是无效的!!
Verify a User’s Email Address Using PHP中提出了另一种解决办法,写自己的函数:
<?php function validate_email($email){ $exp = "^[a-z'0-9]+([._-][a-z'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$"; if(eregi($exp,$email)){ //先用正则表达式验证email格式的有效性 if(checkdnsrr(array_pop(explode("@",$email)),"MX")){//再用checkdnsrr验证email的域名部分的有效性 return true; }else{ return false; } }else{ return false; } } ?>
注意:checkdnsrr函数在win主机上是无效的!!
Verify a User’s Email Address Using PHP中提出了另一种解决办法,写自己的函数:
function myCheckDNSRR($hostName, $recType = '') { if(!empty($hostName)) { if( $recType == '' ) $recType = "MX"; exec("nslookup -type=$recType $hostName", $result); // check each line to find the one that starts with the host // name. If it exists then the function succeeded. foreach ($result as $line) { if(eregi("^$hostName",$line)) { return true; } } // otherwise there was no mail handler for the domain return false; } return false; }
相关文章推荐
- [PHP实例] php Socket发送邮件验证邮箱的真实有效性而非格式
- PHP+Ajax异步通讯实现用户名邮箱验证是否已注册( 2种方法实现)
- php使用filter过滤器验证邮箱 ipv6地址 url验证
- php+js+mysql设计的仿webQQ-<1>邮箱验证
- php 邮箱验证
- PHP验证日常格式_邮箱验证_手机验证_身份正验证_网址验证_时间验证
- PHP+Ajax异步通讯实现用户名邮箱验证是否已注册( 2种方法实现)
- PHP自带方法验证邮箱、URL、IP是否合法的函数
- php中filter函数用法之验证邮箱、url和ip地址
- #学志#[php]验证链接有效性
- 微信开发、PHP服务器有效性验证
- PHP用正则表达式(re)验证邮箱
- php验证邮箱是否合法
- 使用php验证复选框有效性的示例
- 邮箱有效性验证
- PHP 实现 注册等的邮箱验证 (一)—— 加密函数 authcode
- PHP用户注册邮箱并验证激活帐号
- php 过滤器filter_var验证邮箱/url/ip等
- PHP自带方法验证邮箱、URL、IP是否合法的函数
- php实现邮箱验证