ovarun / laravel-disposable-email-validation
Laravel package to detect disposable email addresses using disposable-email-domains list.
Requires
- php: ^8.0
- illuminate/support: ^9.0|^10.0|^11.0
README
A Laravel package to detect and block disposable email addresses using the disposable-email-domains list.
Supports blocklist (domains to block) and allowlist (domains to allow), with auto-sync from GitHub.
π¦ Installation
Install via Composer:
composer require ovarun/laravel-disposable-email
The package uses Laravel Package Auto-Discovery, so you donβt need to register the service provider manually.
βοΈ Configuration
Publish the config file:
php artisan vendor:publish --tag=config
This will create config/disposable-email.php
:
<?php return [ 'blocklist' => [ 'mailinator.com', '10minutemail.com', 'guerrillamail.com', ], 'allowlist' => [ 'gmail.com', 'yahoo.com', 'hotmail.com', 'outlook.com', ], ];
- Blocklist β Domains that should be blocked.
- Allowlist β Domains that are explicitly allowed, even if normally considered disposable.
π Updating Blocklist
This package includes an Artisan command to sync the latest blocklist from GitHub:
php artisan disposable-email:update
The synced list is stored at:
storage/app/disposable-email-blocklist.json
β
Synced domains + your custom config('disposable-email.blocklist')
will be merged together.
β
allowlist
always takes priority over blocklist.
π Usage
Validation Rule
Use the built-in rule in your FormRequest
or controller:
use Ovarun\DisposableEmail\Rules\NotDisposableEmail; $request->validate([ 'email' => ['required', 'email', new NotDisposableEmail], ]);
If the email domain is blocked, the validation will fail with:
Disposable or blocked email addresses are not allowed.
Standalone Check
You can also use the validator class directly:
use Ovarun\DisposableEmail\DisposableEmailValidator; $validator = new DisposableEmailValidator(); if ($validator->isDisposable('test@mailinator.com')) { // Handle blocked email }
β± Optional: Scheduler
To keep your blocklist always up-to-date, schedule the update command in app/Console/Kernel.php
:
protected function schedule(Schedule $schedule) { $schedule->command('disposable-email:update')->weekly(); }
π Example Workflow
-
Install package:
composer require ovarun/laravel-disposable-email
-
Publish config (optional):
php artisan vendor:publish --tag=config
-
Update blocklist:
php artisan disposable-email:update
-
Use rule in validation:
'email' => ['required', 'email', new NotDisposableEmail],
β‘ Features
- β Auto-discovers in Laravel (no manual provider setup)
- β
Configurable
blocklist
andallowlist
- β Artisan command to sync latest domains from GitHub
- β Validation rule for easy integration
- β Standalone class for custom usage
π License
MIT License.
π₯ Ready to keep disposable emails out of your app!