PHP Email验证

  1. <?php
  2. /************************************************************************
  3. *此功能检查格式的电子邮件地址。有5个级别的
  4.  
  5.    *检查:

  6.    * 1 -基本格式检查。确保:
  7.  
  8.    *有一个@符号的东西在左边和右边的东西
  9.  
  10.    *为了正确的@符号,但至少有一个点,与一些左翼和右翼。
  11.  
  12.    *要的权利,最后点或者2个或3个字母,或特殊情况“阿尔帕”
  13.  
  14.    * 2 -以上,再加上信的权利,最后点是:
  15.  
  16.    *通信,网络,组织,教育,大学,人事局,诠释,阿尔帕或一两个字母的国家代码
  17.  
  18.    * 3 -以上,再加上努力,以检查是否存在的MX (邮件交换)记录
  19.  
  20.    *域名。
  21.  
  22.    * 4 -上述情况,加上尝试连接到邮件服务器
  23.  
  24.    * 5 -以上,再加上检查,看看是否有回应的邮件服务器。第三
  25.  
  26.    *论点这一功能是可选的,并提出了多少次循环,而
  27.  
  28.    *等待响应的邮件服务器。默认值为15000 。实际的等待
  29.  
  30.    *时间,当然,依赖于这种事情的速度,您的服务器。
  31.  
  32.    *第1级是防弹:如果该地址没有这个水平,这是坏的。 2级仍然是
  33.  
  34.    *非常稳固,但不太确定:有可能是有效的顶级忽视写作时
  35.  
  36.    *此功能,或新的可以增加。 3级甚至更小一些:有
  37.  
  38.    *一些东西,可以防止找到一个MX记录的一个有效的地址
  39.  
  40.    *在任何特定时间。第4和第5更是某些仍在。归根结底,只有绝对
  41.  
  42.    *积极的方式来测试的电子邮件地址是发送给它。

  43.    *该函数返回0为一个有效的地址,或在哪一级失败,一个
  44.  
  45.    *地址无效。
  46.  
  47.    *
  48.    * This function checks the format of an email address. There are five levels of
  49.    * checking:
  50.    *
  51.    * 1 – Basic format checking. Ensures that:
  52.    *      There is an @ sign with something on the left and something on the right
  53.    *      To the right of the @ sign, there's at least one dot, with something to the left and right.
  54.    *      To the right of the last dot is either 2 or 3 letters, or the special case "arpa"
  55.    * 2 – The above, plus the letters to the right of the last dot are:
  56.    *      com, net, org, edu, mil, gov, int, arpa or one of the two-letter country codes
  57.    * 3 – The above, plus attempts to check if there is an MX (Mail eXchange) record for the
  58.    *      domain name.
  59.    * 4 – The above, plus attempt to connect to the mail server
  60.    * 5 – The above, plus check to see if there is a response from the mail server. The third
  61.    *      argument to this function is optional, and sets the number of times to loop while
  62.    *      waiting for a response from the mail server. The default is 15000. The actual waiting
  63.    *      time, of course, depends on such things as the speed of your server.
  64.    *
  65.    * Level 1 is bulletproof: if the address fails this level, it's bad. Level 2 is still
  66.    * pretty solid, but less certain: there could be valid TLDs overlooked when writing
  67.    * this function, or new ones could be added. Level 3 is even less certain: there are
  68.    * a number of things that could prevent finding an MX record for a valid address
  69.    * at any given time. 4 and 5 are even less certain still. Ultimately, the only absolutely
  70.    * positive way to test an email address is to send something to it.
  71.    *
  72.    * The function returns 0 for a valid address, or the level at which it failed, for an
  73.    * invalid address.
  74.    *
  75.    ************************************************************************/
  76.  
  77.   
    function MailVal($Addr, $Level, $Timeout = 15000) {
    // Valid Top-Level Domains
    $gTLDs = "com:net:org:edu:gov:mil:int:arpa:";
    $CCs = "ad:ae:af:ag:ai:al:am:an:ao:aq:ar:as:at:au:aw:az:ba:bb:bd:be:bf:".
    "bg:bh:bi:bj:bm:bn:bo:br:bs:bt:bv:bw:by:bz:ca:cc:cf:cd:cg:ch:ci:".
    "ck:cl:cm:cn:co:cr:cs:cu:cv:cx:cy:cz:de:dj:dk:dm:do:dz:ec:ee:eg:".
    "eh:er:es:et:fi:fj:fk:fm:fo:fr:fx:ga:gb:gd:ge:gf:gh:gi:gl:gm:gn:".
    "gp:gq:gr:gs:gt:gu:gw:gy:hk:hm:hn:hr:ht:hu:id:ie:il:in:io:iq:ir:".
    "is:it:jm:jo:jp:ke:kg:kh:ki:km:kn:kp:kr:kw:ky:kz:la:lb:lc:li:lk:".
    "lr:ls:lt:lu:lv:ly:ma:mc:md:mg:mh:mk:ml:mm:mn:mo:mp:mq:mr:ms:mt:".
    "mu:mv:mw:mx:my:mz:na:nc:ne:nf:ng:ni:nl:no:np:nr:nt:nu:nz:om:pa:".
    "pe:pf:pg:ph:pk:pl:pm:pn:pr:pt:pw:py:qa:re:ro:ru:rw:sa:sb:sc:sd:".
    "se:sg:sh:si:sj:sk:sl:sm:sn:so:sr:st:su:sv:sy:sz:tc:td:tf:tg:th:".
    "tj:tk:tm:tn:to:tp:tr:tt:tv:tw:tz:ua:ug:uk:um:us:uy:uz:va:vc:ve:".
    "vg:vi:vn:vu:wf:ws:ye:yt:yu:za:zm:zr:zw:"; // The countries can have their own 'TLDs', e.g. mydomain.com.au
    $cTLDs = "com:net:org:edu:gov:mil:co:ne:or:ed:go:mi:"; $fail = 0; // Shift the address to lowercase to simplify checking
    $Addr = strtolower($Addr); // Split the Address into user and domain parts
    $UD = explode("@", $Addr);
    if (sizeof($UD) != 2 || !$UD[0]) $fail = 1; // Split the domain part into its Levels
    $Levels = explode(".", $UD[1]); $sLevels = sizeof($Levels);
    if ($sLevels < 2) $fail = 1; // Get the TLD, strip off trailing ] } ) > and check the length
    $tld = $Levels[$sLevels-1];
    $tld = ereg_replace("[>)}]$|]$", "", $tld);
    if (strlen($tld) < 2 || strlen($tld) > 3 && $tld != "arpa") $fail = 1; $Level–; // If the string after the last dot isn't in the generic TLDs or country codes, it's invalid.
    if ($Level && !$fail) {
    $Level–;
    if (!ereg($tld.":", $gTLDs) && !ereg($tld.":", $CCs)) $fail = 2;
    } // If it's a country code, check for a country TLD; add on the domain name.
    if ($Level && !$fail) {
    $cd = $sLevels - 2; $domain = $Levels[$cd].".".$tld;
    if (ereg($Levels[$cd].":", $cTLDs)) { $cd–; $domain = $Levels[$cd].".".$domain; }
    } // See if there's an MX record for the domain
    if ($Level && !$fail) {
    $Level–;
    if (!getmxrr($domain, $mxhosts, $weight)) $fail = 3;
    } // Attempt to connect to port 25 on an MX host
    if ($Level && !$fail) {
    $Level–;
    while (!$sh && list($nul, $mxhost) = each($mxhosts))
    $sh = fsockopen($mxhost, 25);
    if (!$sh) $fail = 4;
    } // See if anyone answers
    if ($Level && !$fail) {
    $Level–;
    set_socket_blocking($sh, false);
    $out = ""; $t = 0;
    while ($t++ < $Timeout && !$out)
    $out = fgets($sh, 256);
    if (!ereg("^220", $out)) $fail = 5;
    } if ($sh) fclose($sh); return $fail;
    } //MailVal
    ?></span>

注释:MX记录 (Mail Exchange)邮件路由记录

            用户可以将该域名下的邮件服务器指向到自己的mail server上,然后即可自行操作控制所有的邮箱设置。您只需在线填写您服务器的主机名或主机IP地址,即可将您域名下的邮件全部转到您自己设定相应的邮件服务器上。

  这个大家都明白了吗?就是将你的域名中邮件服务器分开,将它设置到其它的IP去!

  比如同样是 cnMonkey_com ,如果你设置A记录是指向123.12.123.123,而MX记录你设置是指向222.22.222.222,那么你的DNS服务器接收到别人的邮件路 由请求时就将会将它的请求解释到222.22.222.222上去!而别人访问你的网页的时候仍然是访问123.12.123.123。 

  可以使用nslookup -qt=mx test_com来解析mx的指向。例子中以test_com为例。

PHP Zend Email验证函数MailVal()函数的使用的更多相关文章

  1. SQL Server 验证身份证合法性函数(使用VBScript.RegExp)

    原文:SQL Server 验证身份证合法性函数(使用VBScript.RegExp) 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wzy0623 ...

  2. php 验证格式的函数总结

    在首页上看到了这篇总结性的文章,就收藏了起来,想转载过来留着以后方便查看,但是没有找到转载的地,就只有copy下来了.在这里谢谢群主的分享! // ※CheckMoney($C_Money) 检查数据 ...

  3. Sass函数--颜色函数--HSL函数

    HSL函数简介HSL颜色函数包括哪些具体的函数,所起的作用是什么: hsl($hue,$saturation,$lightness):通过色相(hue).饱和度(saturation)和亮度(ligh ...

  4. 闭包函数&回调函数

    闭包函数&回调函数 谈到回调函数,不得不提匿名函数;匿名函数,也叫闭包函数,也就是没有名字的函数,它可以单独存在,也可以将其赋值给某一个变量.so,先来看一下闭包函数. 闭包函数 php文档: ...

  5. Python进阶:函数式编程(高阶函数,map,reduce,filter,sorted,返回函数,匿名函数,偏函数)...啊啊啊

    函数式编程 函数是Python内建支持的一种封装,我们通过把大段代码拆成函数,通过一层一层的函数调用,就可以把复杂任务分解成简单的任务,这种分解可以称之为面向过程的程序设计.函数就是面向过程的程序设计 ...

  6. (转)Python进阶:函数式编程(高阶函数,map,reduce,filter,sorted,返回函数,匿名函数,偏函数)

    原文:https://www.cnblogs.com/chenwolong/p/reduce.html 函数式编程 函数是Python内建支持的一种封装,我们通过把大段代码拆成函数,通过一层一层的函数 ...

  7. (查找函数+atoi)判断与(注册函数+strcmp函数)判断两种方法

    loadrunner中接口判断的2中方法    如下: 1. ●查找函数web_reg_find() ● atoi():将字符串转换为整型值 作比较  > 0 Action() { //检查点函 ...

  8. Atitit.跨平台预定义函数 魔术方法 魔术函数 钩子函数 api兼容性草案 v2 q216  java c# php js.docx

    Atitit.跨平台预定义函数 魔术方法 魔术函数 钩子函数 api兼容性草案 v2 q216  java c# php js.docx 1.1. 预定义函数 魔术方法 魔术函数是什么1 1.2. & ...

  9. mysql 函数 时间函数,数学函数,字符串函数,条件判断函数

    =========================================== mysql 相关函数 ============================================= ...

随机推荐

  1. Libevent源码分析系列

    1.使用libevent库     源码那么多,该怎么分析从哪分析呢?一个好的方法就是先用起来,会用了,然后去看底层相应的源码,这样比较有条理,自上向下掌握.下面用libevent库写个程序,每隔1秒 ...

  2. git操作之冲突解决

    应用场景,任哥,我两个人共同修改了git项目上的一个文件.zsh命令行模式 准备工作 简写命令解释 gl=git pullgp=git pushgst=git statusgcmsg=git comm ...

  3. springboot系列八、springboot整合kafka

    背景: 当业务在同一时间出现高并发的时候,这个时候我们不想无限的增加服务器,但是又想提高吞吐量.这时可以考虑使用消息异步处理,进行消峰填谷:同时还可以降低耦合度.常见的消息中间件有kafka,rabb ...

  4. ODOO引用Echarts数据展示

    作为一个后端开发,首先想到的是将需要的数据进行处理反馈给前端. 具体如下: 然后就是专门的echarts模块(我这样写主要是因为echarts会用到的地方比较多,后续直接调用) 1. 2.echart ...

  5. (并发编程)线程 (理论-创建-lock-属性-守护,与进程的对比)

    一.线程理论1.什么是线程   线程指的是一条流水线的工作过程(执行代码)   进程不是执行单位,是资源单位   一个进程内自带一个线程,线程是执行单位 2.进程VS线程    1.同一进程内的线程们 ...

  6. 详解用webpack的CommonsChunkPlugin提取公共代码的3种方式(注意webpack4.0版本已不存在)

    Webpack 的 CommonsChunkPlugin 插件,负责将多次被使用的 JS 模块打包在一起. CommonsChunkPlugin 能解决的问题 在使用插件前,考虑几个问题: 对哪些 c ...

  7. OI中坑点总结

    以下是我个人OI生涯中遇到的坑点的一个小总结,可能是我太菜了,总是掉坑里,请大佬勿喷 1,多重背包的转移的循环顺序 //默认每个物品体积为一(不想打码……) //dp[i]表示占用背包容量i所能获得的 ...

  8. 【C++ Primer 第10章】再探迭代器

    反向迭代器 • 反向迭代器就是在容器中从尾元素向首元素反向移动的迭代器.对于反向迭代器,递增(以及递减)操作的含义会颠倒过来. • 递增一个反向迭代器(++it)会移动到前一个元素:递减一迭代器(-- ...

  9. jquery.Inputmask 插件用法(中文API文档)

      jquery.Inputmask 可以算是input文本输入限制的神器了,内部融合了多种输入限制, 如金额,电话号码,身份证号,网关等..,并且还可以自定义规则. inputmask 据说最早起源 ...

  10. 如何解决海量数据的Top K问题

    1. 问题描述 在大规模数据处理中,常遇到的一类问题是,在海量数据中找出出现频率最高的前K个数,或者从海量数据中找出最大的前K个数,这类问题通常称为“top K”问题,如:在搜索引擎中,统计搜索最热门 ...