Validates email addresses belong to their domains
coodde/laravel-email-checker is a Laravel package for validates email addresses belong to their domains.
It currently has 2 GitHub stars and 6 downloads on Packagist (latest version 0.1.6).
Install it with composer require coodde/laravel-email-checker.
Discover more Laravel packages by coodde
or browse all Laravel packages to compare alternatives.
Last updated
Validates email addresses belong to their domain.
Report Bug
·
Request Feature
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:
Of course, you can always propose new domains to add into listed in the "data" directory.
Key feautures:
This library supports several languages and frameworks.
Simple steps to start use the library.
Check that library works on your PHP version:
Below is an simple list of step to install library.
composer require coodde/laravel-mail-checker
composer.json fileconfig directory, that config file mail-checker.php is createdThis 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
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
See the open issues for a full list of proposed features (and known issues).
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!
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)✅ 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
Distributed under the Apache 2.0 License. See LICENSE for more information.
Svyatoslav Ryzhok - [email protected]
Platform Link: https://coodde.com