Last active
September 9, 2016 10:35
-
-
Save kenzo0107/a33a6e9a75ceb9cf1ccd7213c86db530 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// http://www.tabimoba.net/entry/2014/02/08/154120#.V9JP2pOLS34 | |
// https://github.com/symfony/symfony/issues/18177 | |
// http://qiita.com/ShibuyaKosuke/items/0b9a8fddaefb2060a14a | |
// より精密にフォーマットチェック&DNSチェック | |
// 利用できる特殊記号 半角英数字 . _ - | |
function checkEmailwithDNS($email, $check_dns = false) { | |
switch (true) { | |
case !filter_var($email, FILTER_VALIDATE_EMAIL): | |
case !preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email): | |
case !preg_match('/@([\w.-]++)\z/', $email, $m): | |
return false; | |
case !$check_dns: | |
case checkdnsrr($m[1], 'MX'): | |
case checkdnsrr($m[1], 'A'): | |
case checkdnsrr($m[1], 'AAAA'): | |
return true; | |
default: | |
return false; | |
} | |
} | |
$emails = array( | |
'[email protected]' | |
,'[email protected]' | |
,'a"[email protected]' | |
,'a@[email protected]' | |
,'a#[email protected]' | |
,'[email protected]' | |
,'a%[email protected]' | |
,'a&[email protected]' | |
,'a`[email protected]' | |
,'a([email protected]' | |
,'a)[email protected]' | |
,'[email protected]' | |
,'[email protected]' | |
,'[email protected]' | |
,'a|[email protected]' | |
,'a\[email protected]' | |
,'a^[email protected]' | |
,'a:[email protected]' | |
,'a;[email protected]' | |
,'a*[email protected]' | |
,'[email protected]' | |
,'[email protected]' | |
,'a<[email protected]' | |
,'a>[email protected]' | |
,'a>[email protected]' | |
,'a,[email protected]' | |
,'a`[email protected]' | |
,'a[[email protected]' | |
,'a][email protected]' | |
,'a{[email protected]' | |
,'a}[email protected]' | |
,'a}[email protected]' | |
,'¥[email protected]' | |
,'[email protected]' | |
,'"[email protected]' | |
,'@[email protected]' | |
,'#[email protected]' | |
,'[email protected]' | |
,'%[email protected]' | |
,'&[email protected]' | |
,'([email protected]' | |
,')[email protected]' | |
,'[email protected]' | |
,'[email protected]' | |
,'|[email protected]' | |
,'\[email protected]' | |
,'^[email protected]' | |
,':[email protected]' | |
,';[email protected]' | |
,'*[email protected]' | |
,'[email protected]' | |
,'[email protected]' | |
,'<[email protected]' | |
,'>[email protected]' | |
,',[email protected]' | |
,'`[email protected]' | |
,'[[email protected]' | |
,'][email protected]' | |
,'{[email protected]' | |
,'}[email protected]' | |
,'[email protected]' | |
,'[email protected]' | |
,'[email protected]' | |
,'[email protected]' | |
,'abc@@vwx.yz' | |
,'[email protected]' | |
); | |
$ng_emails = array(); | |
$ok_emails = array(); | |
foreach ($emails as $email) { | |
if (checkEmailwithDNS($email, true)) { | |
// echo '(^-^):'.$email."\n"; | |
$ok_emails[] = $email; | |
} else { | |
// echo '(>_<):'.$email."\n"; | |
$ng_emails[] = $email; | |
} | |
} | |
echo "\n[OK (^-^) EMAIL LIST]\n"; | |
if (!empty($ok_emails)) { | |
foreach ($ok_emails as $email) { | |
echo $email."\n"; | |
} | |
} | |
echo "\n[NG (>_<) EMAIL LIST]\n"; | |
if (!empty($ng_emails)) { | |
foreach ($ng_emails as $email) { | |
echo $email."\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment