Laravel Email Shield is a highly extensible, framework-native email authenticity and validation engine for Laravel.
It protects your application from junk sign-ups, disposable/throwaway addresses, role-based accounts, and dead domains by executing a high-performance validation pipeline that fails fast on simple syntax checks before ever executing slow network DNS lookups. Furthermore, it intelligently caches DNS checks to prevent throttling and rate limits during high traffic.
You can install the package via composer:
composer require unctom/laravel-email-shieldThe most common way to use Laravel Email Shield is via the provided EmailAuthentic validation rule during form requests.
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use Unctom\EmailShield\Rules\EmailAuthentic;
Route::post('/register', function (Request $request) {
$request->validate([
'email' => [
'required',
'string',
'email',
(new EmailAuthentic())
->notDisposable() // Blocks mailinator, tempmail, etc.
->preventRoleBased() // Blocks admin@, support@, info@, etc.
->requireMx(), // Ensures the domain has valid MX or A records
],
]);
// ...
});If you need to validate an email address outside of Laravel's validation system, you can use the EmailShield facade directly:
use Unctom\EmailShield\Facades\EmailShield;
$result = EmailShield::validate('developer@example.com', [
'check_disposable' => true,
'prevent_role_based' => true,
'require_mx' => true,
]);
if (! $result->isValid()) {
echo "Validation failed: " . $result->getErrorMessage();
echo "Failed at step: " . $result->getFailedRule();
}composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.