A Laravel package for validating email addresses using the UserCheck.com API.
- Block disposable email addresses with an always up-to-date API
- Validate email addresses
- Check for MX records
- Identify personal email addresses
- Block email forwarding services
- Block domains marked as spam
- Blocks custom domains (Paid plans only)
- Customizable validation rules
- Laravel Facade for easy use
- Localization support
- PHP 8.0+
- Laravel 11.0+
Install the package via Composer:
composer require usercheck/usercheck-laravelAdd your UserCheck API key to your .env file:
USERCHECK_API_KEY=your_api_key_hereYou can obtain a free API key by signing up at https://app.usercheck.com/register.
Use the usercheck rule in your Laravel validation:
$request->validate([
'email' => 'required|email|usercheck'
]);By default, the usercheck rule will only validate the email address's syntax using the UserCheck API. If the email is invalid, the validation will fail.
The usercheck rule accepts several parameters:
block_disposable: Fails validation if the email is from a disposable email providerblock_no_mx: Fails validation if the domain has no MX recordsblock_public_domain: Fails validation for public email domains (e.g., Gmail, Yahoo). Great to prevent users from signing up with their personal email addresses.block_relay_domain: Blocks email addresses from email forwarding servicesblock_spam: Blocks email addresses from domains that have been marked as spamdomain_only: Validates only the domain part of the email. Great for privacy; only the domain will be sent to the API.block_blocklisted: (Paid plans only) Blocks domains from your custom blocklist.
You can combine these options to create a custom validation rule:
$request->validate([
'email' => 'required|email|usercheck:domain_only,block_disposable,block_no_mx,block_spam',
]);You can also use the UserCheck facade directly:
use UserCheck\Laravel\Facades\UserCheck;
$result = UserCheck::validateEmail('test@example.com');
$result = UserCheck::validateDomain('example.com');Both methods return an array with is_valid and error_code keys.
The package includes English translations by default. To customize the error messages, publish the language files:
php artisan vendor:publish --provider="UserCheck\Laravel\UserCheckProvider" --tag="lang"Then, edit the files in resources/lang/vendor/usercheck.
Run the tests with:
composer testContributions are welcome! Please see CONTRIBUTING.md for details.
If you discover any security-related issues, please email security@usercheck.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
For support, please email support@usercheck.com or open an issue on GitHub.