beeyev/disposable-email-filter-php
Composer 安装命令:
composer require beeyev/disposable-email-filter-php
包简介
Disposable (temporary/throwaway/fake) email detection library. Automatically updated every week.
README 文档
README
PHP package that detects disposable (temporary/throwaway/fake) email addresses. It is framework-agnostic and has no dependencies, but includes support for Laravel.
It validates email addresses to ensure they are genuine, which is useful for managing account sign-ups and assessing the number of legitimate email addresses in your system.
This tool also helps to avoid communication errors and blocks spam addresses.
🚀 The lookup is superfast O(1) because disposable email domains are stored locally using a native PHP hash set..
🚡 The list of disposable email domains is regularly updated automatically from trusted external sources.
📦 Installation and Usage examples
Note
Read below for Laravel specific instructions.
Require this package with composer using the following command:
composer require beeyev/disposable-email-filter-php
Basic usage
Simple check if the email address is disposable:
<?php require __DIR__ . '/vendor/autoload.php'; use Beeyev\DisposableEmailFilter\DisposableEmailFilter; $disposableEmailFilter = new DisposableEmailFilter(); // Check if email address is disposable $disposableEmailFilter->isDisposableEmailAddress('ostap@gmail.com'); // false $disposableEmailFilter->isDisposableEmailAddress('john@tempmailer.com'); // true
Adding custom disposable(blacklisted) and whitelisted domains:
Note: Whitelisted domains have higher priority than blacklisted domains.
<?php require __DIR__ . '/vendor/autoload.php'; use Beeyev\DisposableEmailFilter\DisposableEmailFilter; $disposableEmailFilter = new DisposableEmailFilter(); // Add multiple custom domains to blacklist $disposableEmailFilter->blacklistedDomains()->addMultiple(['mailinator.com', '10minute-mail.org']); // Add one domain to whitelist $disposableEmailFilter->whitelistedDomains()->add('tempmailer.com'); $disposableEmailFilter->isDisposableEmailAddress('john@tempmailer.com'); // false (because it's whitelisted now) $disposableEmailFilter->isDisposableEmailAddress('john@mailinator.com'); // true $disposableEmailFilter->isDisposableEmailAddress('john@10minute-mail.org'); // true $disposableEmailFilter->isDisposableEmailAddress('john@gmail.com'); // false
It is also possible to add blacklisted and whitelisted domains using constructor dependency:
use Beeyev\DisposableEmailFilter\CustomEmailDomainFilter\CustomEmailDomainFilter; use Beeyev\DisposableEmailFilter\DisposableEmailFilter; $blacklistedDomains = new CustomEmailDomainFilter(['blacklisted1.com', 'blacklisted2.com', 'blacklisted3.com']); $whitelistedDomains = new CustomEmailDomainFilter(['abc2.com', 'whitelisted1.com']); $disposableEmailFilter = new DisposableEmailFilter($blacklistedDomains, $whitelistedDomains); $disposableEmailFilter->isDisposableEmailAddress('test@whitelisted1.com'); // false - whitelisted
Note: You can develop your own filtration logic by creating a custom class that implements the
CustomEmailDomainFilterInterface
Handling exceptions:
If you try to pass empty string or string with invalid email format, an exception will be thrown.
use Beeyev\DisposableEmailFilter\DisposableEmailFilter; use Beeyev\DisposableEmailFilter\Exceptions\InvalidEmailAddressException; $disposableEmailFilter = new DisposableEmailFilter(); try { $disposableEmailFilter->isDisposableEmailAddress('john:gmail.com'); // Exception will be thrown because of invalid email format } catch (InvalidEmailAddressException $e) { echo $e->getMessage(); }
If you expect that email address might be invalid and don't want to wrap the code into try/catch,
you can use isDisposableEmailAddressSafe method to check if email address is correctly formatted before checking if it's disposable:
$disposableEmailFilter = new DisposableEmailFilter(); $emailAddress = 'john:gmail.com'; if ($disposableEmailFilter->isEmailAddressValid($emailAddress)) { $disposableEmailFilter->isDisposableEmailAddress($emailAddress); }
Laravel specific usage
This package includes a service provider and form validation rule for Laravel.
Install the package (Laravel)
composer require beeyev/disposable-email-filter-php
The package will be automatically registered using Laravel auto-discovery mechanism.
But if you need to do it manually, you can add the following line to the providers array in the config/app.php file:
Beeyev\DisposableEmailFilter\Adapters\Laravel\DisposableEmailFilterServiceProvider::class,
Form validation (Laravel)
Use validation rule not_disposable_email or object new NotDisposableEmail(),
to check that specific field does not contain a disposable email address.
Note
❗ Place it after the email validator to ensure that only valid emails are processed.
Example:
// Using validation rule name: 'email_field' => 'required|email|not_disposable_email', // Or using a validation rule object: 'email_field' => ['email', new NotDisposableEmail()],
Using facades (Laravel)
You can use the DisposableEmail facade to access the DisposableEmailFilter instance:
use Beeyev\DisposableEmailFilter\Adapters\Laravel\Facades\DisposableEmail; DisposableEmail::isEmailAddressValid('foo@fakemail.com');
Config file and translations (Laravel)
Optionally, you can publish the config file and translations to customize the package behavior:
php artisan vendor:publish --tag=disposable-email-filter
This command will create a disposable-email-filter.php config file in the config directory
and translation files in the lang/vendor/disposable-email-filter directory.
Updating
Since the list of disposable email domains is regularly updated, it is important to keep the package up to date.
A new PATCH version of the package is released whenever the list is updated.
These updates are safe and non-breaking, allowing you to update the package via this composer command:
composer update beeyev/disposable-email-filter-php
You can run this command every time in CI/CD pipelines before the project is deployed.
Contribution
Feel free to contribute to this project if you want to add new features, improve existing ones, or fix bugs.
To add new disposable domains, you can update the blacklist.txt file and create a pull request.
Alternatively, you can open an issue with the domains you want to be added to the blacklist or whitelist.
External Sources:
Local blacklist and whitelist are stored in the blacklist.txt and whitelist.txt files.
Issues
Bug reports and feature requests can be submitted on the Github Issue Tracker.
© License
The MIT License (MIT). Please see License File for more information.
If you love this project, please consider giving me a ⭐
beeyev/disposable-email-filter-php 适用场景与选型建议
beeyev/disposable-email-filter-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 221.73k 次下载、GitHub Stars 达 72, 最近一次更新时间为 2024 年 05 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「fake」 「temporary」 「throwaway」 「disposable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 beeyev/disposable-email-filter-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 beeyev/disposable-email-filter-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 beeyev/disposable-email-filter-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Mocks, stubs, and spies for PHP.
Phony for Kahlan.
The Hiqdev Hoa\File library.
Make temporary Laravel workarounds expire and fail CI when ignored.
Temporary URL resource server for rekalogika/file FileInterface. Access files easily in your application by creating temporary URLs that expire after a set amount of time.
Mock PSR-18 HTTP client
统计信息
- 总下载量: 221.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 72
- 点击次数: 28
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-26