coodde/laravel-email-checker
Composer 安装命令:
composer require coodde/laravel-email-checker
包简介
Validates email addresses belong to their domains
README 文档
README
Laravel Email Checker
Validates email addresses belong to their domain.
Report Bug
·
Request Feature
Table of Contents
About The Project
Flexible and simple library for checking email addresses. Usual framework validators are usually checking email correctness, but this library is implementing other kind of validation.
It can check is mail:
- registered in mail provider from forbidden country;
- registered in forbidden domain (all possible levels);
- used for spam or scam (dangerous), temporary, had suspicious behaviour, is registered on paid or public (like gmail) mail provider.
Of course, you can always propose new domains to add into listed in the "data" directory.
Key feautures:
- fast search - binary search in the pre-sorted dictionaries (in comparison with other popular libraries with linear search)
- flexible configurations - not only one strict list
- low memory usage - disctionaries are not loaded fully into memory (as in other popular libraries)
- frequent updates
- easy collaboration
- large disctionary- 60k+ of domains (not only public email providers) in the dictionary
Built With
This library supports several languages and frameworks.
- PHP
- JS / TS
- Ruby
- Ruby on Rails (planned)
- Perl
- Vanilla (planned)
Getting Started
Simple steps to start use the library.
Requires
Check that library works on your PHP version:
- PHP 8.0+
- Composer
Installation
Below is an simple list of step to install library.
- Open your project directory in the terminal
- Install package
composer require coodde/laravel-mail-checker
- Check your
composer.jsonfile - Check your app.php, that ServiceProvider is installed
- Check your
configdirectory, that config filemail-checker.phpis created
Usage
This table will help to understand possible usage of library and all default values:
| Params | Validator classes | Validator names | Default Value | Possible Values | Description |
|---|---|---|---|---|---|
| categories | Coodde\LaravelMailChecker\Rules\MailListedValidationCoodde\LaravelMailChecker\Rules\MailValidation |
mail_check_listed, mail_check |
[Regions::CATEGORY_DANGEROUS] | MailListedValidator::CATEGORY_PUBLIC MailListedValidator::CATEGORY_PAID MailListedValidator::CATEGORY_TEMPORARY MailListedValidator::CATEGORY_SUSPICIOUS MailListedValidator::CATEGORY_DANGEROUS |
For more comfortable usage all mail providers are split into several lists |
| domains | Coodde\LaravelMailChecker\Rules\MailDomainsValidationCoodde\LaravelMailChecker\Rules\MailValidation |
mail_check_domains, mail_check |
[] | * | Any kind of domains, starting by top level domains like "com" or "net", and finishing by exact domains like "mail.ru" |
| regions | Coodde\LaravelMailChecker\Rules\MailRegionsValidationCoodde\LaravelMailChecker\Rules\MailValidation |
mail_check_regions, mail_check |
[ Regions::RUSSIA, Regions::BELARUS, Regions::NORTH_KOREA, Regions::AFGHANISTAN, Regions::IRAN, Regions::SYRIA, Regions::SOVIET_UNION, Regions::CUBA ] | All Available Regions
|
Recommended to use constants for easier code maintenance |
Here you will find different cases of usage.
Checking that mail address registered in Russian mail provider:
use Coodde\LaravelMailChecker\Rules\MailRegionsValidation; use Coodde\LaravelMailChecker\Regions; public function store(Request $request): RedirectResponse { $validated = $request->validate([ 'email' => ['required', new MailRegionsValidation([Regions::RUSSIA])], ]); // OR with configs from env, ex. (country code) - MAIL_CHECKER_REGIONS=ru $validated = $request->validate([ 'email' => ['required', new MailRegionsValidation()], ]); // Request is valid... return redirect('/list'); }
Checking that mail address registered in "ru" or "mail.by" domains:
use Coodde\LaravelMailChecker\Rules\MailDomainsValidation; use Coodde\LaravelMailChecker\Regions; public function store(Request $request): RedirectResponse { $validated = $request->validate([ 'email' => ['required', new MailDomainsValidation(['ru', 'mail.by'])], ]); // OR with configs from env, ex. - MAIL_CHECKER_DOMAINS=ru,mail.by $validated = $request->validate([ 'email' => ['required', new MailDomainsValidation()], ]); // Request is valid... return redirect('/list'); }
Checking that mail address is placed in dangerous or suspicious lists:
use Coodde\LaravelMailChecker\Rules\MailListedValidation; use Coodde\LaravelMailChecker\Regions; public function store(Request $request): RedirectResponse { $validated = $request->validate([ 'email' => ['required', new MailListedValidation([MailListedValidation::CATEGORY_DANGEROUS, MailListedValidation::CATEGORY_SUSPICIOUS])], ]); // OR with configs from env, ex. - MAIL_CHECKER_CATEGORIES=dangerous,suspicious $validated = $request->validate([ 'email' => ['required', new MailListedValidation()], ]); // Request is valid... return redirect('/list'); }
Complex validation to allow only corporate emails, :
use Coodde\LaravelMailChecker\Rules\MailValidation; use Coodde\LaravelMailChecker\Regions; public function store(Request $request): RedirectResponse { $validated = $request->validate([ 'email' => [ 'required', new MailValidation( [ MailListedValidation::CATEGORY_DANGEROUS, MailListedValidation::CATEGORY_SUSPICIOUS, MailListedValidation::CATEGORY_TEMPORARY, MailListedValidation::CATEGORY_PAID, MailListedValidation::CATEGORY_PUBLIC, ], [ 'fb.com', ], [ Regions::RUSSIA, Regions::BELARUS, ], ), ], ]); // OR with separate validators $validated = $request->validate([ 'email' => [ 'required', new MailListedValidation([ MailListedValidation::CATEGORY_DANGEROUS, MailListedValidation::CATEGORY_SUSPICIOUS, MailListedValidation::CATEGORY_TEMPORARY, MailListedValidation::CATEGORY_PAID, MailListedValidation::CATEGORY_PUBLIC, ]), new MailDomainsValidation([ 'fb.com', ]), new MailRegionsValidation([ Regions::RUSSIA, Regions::BELARUS, ]), ], ]); // Request is valid... return redirect('/list'); }
Of course you can combine restrictioned domains, countries, and categories
Roadmap
- Checking by countries
- Checking by domains
- Prepared lists
- Dangerous - usually scaming servers / domains
- Suspicios - usually spaming servers / domains
- Paid - mail providers with non-free subscription
- Temporary - services for mails which will be removed soon after creation
- Public - popular free services like gmail, outlook, etc
- Checking by prepaired lists
- From files - it uses binary search without file content buffering
- From cache - cache files with lists compiled into php file
- From memory - storing lists in memcache
- From database - by using PDO library+
See the open issues for a full list of proposed features (and known issues).
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
✅ Run refactors using Rector
composer refacto
⚗️ Run static analysis using PHPStan:
composer test:types
✅ Run unit tests using PEST
composer test:unit
🚀 Run the entire test suite:
composer test
Top contributors:
License
Distributed under the Apache 2.0 License. See LICENSE for more information.
Contact
Svyatoslav Ryzhok - info@coodde.com
Platform Link: https://coodde.com
coodde/laravel-email-checker 适用场景与选型建议
coodde/laravel-email-checker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「validator」 「validation」 「laravel」 「email domain」 「email checker」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 coodde/laravel-email-checker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 coodde/laravel-email-checker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 coodde/laravel-email-checker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Runn Me! Validation and Sanitization Library
Extension for Opis JSON Schema
Adds request-parameter validation to the SLIM 3.x PHP framework
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
A jQuery augmented PHP library for creating and validating HTML forms
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-11-26