beeyev / disposable-email-filter-php
Disposable (temporary/throwaway/fake) email detection library. Automatically updated every week.
Installs: 17 360
Dependents: 0
Suggesters: 0
Security: 0
Stars: 41
Watchers: 2
Forks: 2
Open Issues: 2
Requires
- php: ^7.2 || ^8.0
Requires (Dev)
- ext-json: *
- friendsofphp/php-cs-fixer: ^3.4
- kubawerlos/php-cs-fixer-custom-fixers: ^3.7
- phpstan/phpstan: ^1.11
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpunit: ^8.5 || ^9
- symplify/phpstan-rules: ^12.3
- dev-master
- v1.3.68
- v1.3.67
- v1.3.66
- v1.3.65
- v1.3.64
- v1.3.63
- v1.3.62
- v1.3.61
- v1.3.60
- v1.3.59
- v1.3.58
- v1.3.57
- v1.3.56
- v1.3.55
- v1.3.54
- v1.3.53
- v1.3.52
- v1.3.51
- v1.3.50
- v1.3.49
- v1.3.48
- v1.3.47
- v1.3.46
- v1.3.45
- v1.3.44
- v1.3.43
- v1.3.42
- v1.3.41
- v1.3.40
- v1.3.39
- v1.3.38
- v1.3.37
- v1.3.36
- v1.3.35
- v1.3.34
- v1.3.33
- v1.3.32
- v1.3.31
- v1.3.30
- v1.3.29
- v1.3.28
- v1.3.27
- v1.3.26
- v1.3.25
- v1.3.24
- v1.3.23
- v1.3.22
- v1.3.21
- v1.3.20
- v1.3.19
- v1.3.18
- v1.3.17
- v1.3.16
- v1.3.15
- v1.3.14
- v1.3.13
- v1.3.12
- v1.3.11
- v1.3.10
- v1.3.9
- v1.3.8
- v1.3.7
- v1.3.6
- v1.3.5
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- dev-filter-list-update/2024-12-22_11-22-22_(UTC)
- dev-filter-list-update/2024-12-07_11-24-30_(UTC)
- dev-dependabot/github_actions/codecov/codecov-action-5
- dev-filter-list-update/2024-09-25_11-25-25_(UTC)
- dev-filter-list-update/2024-09-22_11-22-43_(UTC)
- dev-filter-list-update/2024-07-23_19-04-33_(UTC)
This package is auto-updated.
Last update: 2024-12-22 11:35:42 UTC
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 ⭐