mischasigtermans / laravel-sift
Extract and filter common email domains in Laravel.
Requires
- php: ^8.0
- illuminate/support: ^9.0|^10.0|^11.0
Requires (Dev)
- laravel/pint: ^1.20
- orchestra/testbench: ^8.31
- pestphp/pest: ^2.36
- pestphp/pest-plugin-laravel: ^2.4
README
Sift is a Laravel package for extracting and filtering email domains. Whether you're handling user registrations, blocking public email providers, or ensuring only business emails are used, Sift makes it simple.
Features
- Domain Extraction → Extracts the domain from any email address.
- Smart Filtering → Automatically detects and filters out public/free email providers.
- Handles Major Providers → Includes Gmail, Yahoo, Outlook, and many more out of the box.
- Customizable → Easily modify the list of common domains in the config file.
- Laravel-Optimized → Designed for seamless integration with Laravel.
Installation
Install Sift via Composer:
composer require mischasigtermans/laravel-sift
Note: Laravel auto-discovers the package, so no manual setup is needed.
To publish the config file:
php artisan vendor:publish --tag=sift-config
This creates config/sift.php
, allowing customization of filtered domains.
Usage
Extract an email's domain
use Sift; Sift::domain('user@example.com'); // Returns 'example.com' // By default, public email domains are filtered: Sift::domain('user@gmail.com'); // Returns null // Allow public domains explicitly: Sift::domain('user@gmail.com', true); // Returns 'gmail.com' // Business email remains unaffected: Sift::domain('user@company.com'); // Returns 'company.com'
Check if a domain is common
Sift::isCommon('gmail.com'); // true Sift::isCommon('user@company.com'); // false Sift::isCommon('invalid-email'); // null
Blade Example
{{ Sift::domain('hello@company.org') }}
Configuration
Modify the common domain list in config/sift.php
after publishing the config:
return [ 'additional_domains' => [ // 'example.org', 'testmail.com' ], 'common_domains' => [ 'gmail.com', 'yahoo.com', 'outlook.com', 'hotmail.com', 'icloud.com', 'protonmail.com', 'zoho.com', 'gmx.com', 'aol.com', 'yandex.com', 'qq.com', 'live.com', 'rediffmail.com', 'mail.com', 'bigmir.net', // (Full list continues...) ], ];
View the full list of common domains in the configuration file here.
Running Tests
Sift includes lightweight but effective tests using Pest. To run them:
vendor/bin/pest
Contributing
Contributions are welcome. If you spot missing providers or have improvements, feel free to:
- Open an issue on GitHub
- Submit a pull request
License
Sift is open-source software licensed under the MIT License.