php检查电子邮件是否正确,如何使用PHP检查电子邮件地址是真实还是有效

e8b4f698159743d3324396e20c1d6a23.png

慕田峪9158850

我整个上午一直在寻找同样的答案,并且几乎发现在您需要验证它时,您可能无法验证您需要检查的每个电子邮件地址是否确实存在。因此,作为一种解决方法,我创建了一个简单的PHP脚本来验证电子邮件地址的格式是否正确,并且还验证了所使用的域名也是正确的。GitHub这里https://github.com/DukeOfMarshall/PHP---JSON-Email-Verification/tree/master<?php # What to do if the class is being called directly and not being included in a script     via PHP# This allows the class/script to be called via other methods like JavaScriptif(basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"])){$return_array = array();if($_GET['address_to_verify'] == '' || !isset($_GET['address_to_verify'])){    $return_array['error']              = 1;    $return_array['message']            = 'No email address was submitted for verification';    $return_array['domain_verified']    = 0;    $return_array['format_verified']    = 0;}else{    $verify = new EmailVerify();    if($verify->verify_formatting($_GET['address_to_verify'])){        $return_array['format_verified']    = 1;        if($verify->verify_domain($_GET['address_to_verify'])){            $return_array['error']              = 0;            $return_array['domain_verified']    = 1;            $return_array['message']            = 'Formatting and domain have been verified';        }else{            $return_array['error']              = 1;            $return_array['domain_verified']    = 0;            $return_array['message']            = 'Formatting was verified, but verification of the domain has failed';        }    }else{        $return_array['error']              = 1;        $return_array['domain_verified']    = 0;        $return_array['format_verified']    = 0;        $return_array['message']            = 'Email was not formatted correctly';    }}echo json_encode($return_array);exit();}class EmailVerify {public function __construct(){}public function verify_domain($address_to_verify){    // an optional sender      $record = 'MX';    list($user, $domain) = explode('@', $address_to_verify);    return checkdnsrr($domain, $record);}public function verify_formatting($address_to_verify){    if(strstr($address_to_verify, "@") == FALSE){        return false;    }else{        list($user, $domain) = explode('@', $address_to_verify);        if(strstr($domain, '.') == FALSE){            return false;        }else{            return true;        }    }    }}?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值