Merge pull request #170 from Wruczek/patch-1

Updated PHP code snippet
This commit is contained in:
Martin Cech 2018-07-11 00:06:51 -04:00 committed by GitHub
commit 18ec729dcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,14 +31,16 @@ Available as [PyPI module](https://pypi.org/project/disposable-email-domains) th
True True
``` ```
**PHP** contributed by [@txt3rob](https://github.com/txt3rob), [@deguif](https://github.com/deguif) and [@pjebs](https://github.com/pjebs) **PHP** contributed by [@txt3rob](https://github.com/txt3rob), [@deguif](https://github.com/deguif), [@pjebs](https://github.com/pjebs) and [@Wruczek](https://github.com/Wruczek)
1. Make sure the passed email is valid. You can check that with [filter_var](https://secure.php.net/manual/en/function.filter-var.php)
2. Make sure you have the mbstring extension installed on your server
```php ```php
function is_disposable_email($email) { function isDisposableEmail($email, $blacklist_path = null) {
$path = realpath(dirname(__FILE__)) . '/disposable_email_blacklist.conf'; if (!$blacklist_path) $blacklist_path = __DIR__ . '/disposable_email_blacklist.conf';
$mail_domains_ko = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $disposable_domains = file($blacklist_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$mail_domains_ko = array_fill_keys($mail_domains_ko, true); $domain = mb_strtolower(explode('@', trim($email))[1]);
$domain = mb_strtolower(explode('@', trim($email))[1]); return in_array($domain, $disposable_domains);
return (isset($mail_domains_ko[$domain]) || array_key_exists($domain, $mail_domains_ko));
} }
``` ```
**Ruby on Rails** contributed by [@MitsunChieh](https://github.com/MitsunChieh) **Ruby on Rails** contributed by [@MitsunChieh](https://github.com/MitsunChieh)