慕田峪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; } } }}?>