Validate emails against multiple databases with disposable email domains.
Current databases (domains, wildcard and whitelist):
- https://github.com/ivolo/disposable-email-domains
- https://github.com/MattKetmo/EmailChecker
- https://github.com/fgribreau/mailchecker
- https://github.com/martenson/disposable-email-domains
Via Composer:
composer require eusonlito/disposable-email-validator
Basic use of email validator against built-in domains list:
<?php
require __DIR__.'/vendor/autoload.php';
use Eusonlito\DisposableEmail\Check;
// Simple
// Validate emailFilter, domain and wildcard
Check::email('me@my-email.com'); // true
Check::email('me@10minutemail.com'); // false
// Other methods
Check::emailFilter('me@my-email.com'); // Validate email with filter_var
Check::emailExpression('me@my-email.com'); // Validate email with regular expression
Check::domain('my-email.com'); // Validate domain and wildcard domains
Check::wildcard('my-email.com'); // Validate only wildcard domains
To integrate this library with your Laravel 5.x project add the following
line to the providers
key within your config/app.php
file:
'providers' => [
...
Eusonlito\DisposableEmail\Laravel\DisposableEmailServiceProvider::class
...
];
You can then use the library within your project like so:
<?php
use InvalidArgumentException;
use Eusonlito\DisposableEmail\Check;
class Signup
{
public function validate(Request $request)
{
if (!Check::email($request->input('email'))) {
throw new InvalidArgumentException('Invalid email');
}
}
public function getValidator(array $data)
{
return Validator::make($data, [
'email' => 'required|email|disposable_email' // Use after email validator
]);
}
}