Prevent Disposable Email Registrations with Email Utilities for Laravel
Last updated on by Yannick Lyn Fatt
Email Utilities is a small Laravel package created by Ash Allen that facilitates interactions with email addresses. A common use case for this package is on public-facing forms, where it can help prevent users from submitting email addresses from disposable email providers. Another use case is for checking for Role-based email addresses that are not specific to an individual
Note: This package is not a replacement for Laravel's built-in email validator but should be used alongside it. It offers additional utilities for managing email addresses.
Features
- Determine if a user is attempting to use a disposable email address (e.g.,
test@0-mail.com). - Check whether a given email address is role-based (e.g.,
admin@,support@,info@, andsales@). - Validate the domain of an email address using methods like
domainIsanddomainIsNot. - Provide additional validation rules that complement Laravel's built-in email validator.
- Allow configuration of disposable email domains and role accounts lists.
Example
use AshAllenDesign\EmailUtilities\Email;use AshAllenDesign\EmailUtilities\Rules\EmailDomainIs; // Check if an email is disposablenew Email('hello@0-mail.com')->isDisposable(); // Check if an email is role-basednew Email('support@example.com')->isRoleAccount(); // Check the domain of an email addressnew Email('test@test.com')->domainIs(['example.com', 'test.com']); // Validation$request->validate([ 'email' => [ 'required', 'email', new EmailDomainIs(patterns: ['example.com', '*.example.com']) ],]);
Install the package via Composer and publish the configuration file using the following commands:
composer require ashallendesign/email-utilitiesphp artisan php artisan vendor:publish --tag=email-utilities-config
Learn more about this package and view the source code on GitHub.