Skip to content

Repository files navigation

EmailChecker

Code quality...DownloadsPackagistLicense MIT

PHP library to check if an email comes from a disposable email provider.

To detect invalid emails, it provides a built-in database of 1000+ disposable email providers, but you can also use your own data.

Installation

Via Composer:

composer require mattketmo/email-checker

Usage

Basic use of EmailChecker with built-in throwaway email list:

<?phprequire__DIR__.'/vendor/autoload.php';
useEmailChecker\EmailChecker;
$checker = newEmailChecker();
$checker->isValid('foo@bar.org'); // true$checker->isValid('foo@yopmail.com'); // false

Or using a custom adapter:

<?phpuseEmailChecker\EmailChecker;
useEmailChecker\Adapter;
$checker = newEmailChecker(newAdapter\ArrayAdapter(array(
'foo.org',
'baz.net'
)));
$checker->isValid('foo@bar.org'); // true$checker->isValid('foo@baz.net'); // false

You can build your own adapter (to use another database) simply by implementing the AdapterInterface.

Integration with Symfony

This library also provides a constraint validation for your Symfony project:

<?phpuseEmailChecker\ConstraintsasEmailCheckerAssert;
useSymfony\Component\Validator\ConstraintsasAssert;
class User
{
#[Assert\NotBlank] #[EmailCheckerAssert\NotThrowawayEmail] privatestring$email;
}

Integration with Laravel

To integrate this library with your Laravel project add the following line to the providers key within your config/app.php file:

EmailChecker\Laravel\EmailCheckerServiceProvider::class

If you would like to use the EmailChecker facade, you must also add the following line to the aliases key within your config/app.php file:

'EmailChecker' => EmailChecker\Laravel\EmailCheckerFacade::class

You can then use the library within your project like so:

<?phpclass MyClass
{
publicfunctionfoo()
{
// Facade Access
EmailChecker::isValid('address@domain.com');
// Container Access$checker = app()->make('email.checker');
$checker->isValid('address@domain.com');
}
publicfunctiongetValidator(array$data)
{
// Not thow away validatorreturn Validator::make($data, [
'email' => 'required|email|not_throw_away'
]);
}
}

List of some disposable emails database

License

EmailChecker is released under the MIT License. See the bundled LICENSE file for details.

About

Disposable email detection library for PHP

Resources

Stars

275 stars

Watchers

13 watching

Forks

Releases

Packages

Used by

Contributors

Languages