/EmailChecker

Disposable email detection library for PHP + Symfony

Primary LanguagePHPMIT LicenseMIT

EmailChecker

Build Status

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

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

Note: this library is inspired from FGRibreau/mailchecker, except it only focuses on PHP (and integration with Symfony).

Installation

Via Composer:

composer require "mattketmo/email-checker:~0.1"

Usage

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

<?php

require __DIR__.'/vendor/autoload.php';

use EmailChecker\EmailChecker;

$checker = new EmailChecker();

$checker->isValid('foo@bar.org');     // true
$checker->isValid('foo@yopmail.com'); // false

Or using another adapter:

<?php

use EmailChecker\EmailChecker;
use EmailChecker\Adapter;

$checker = new EmailChecker(new Adapter\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 Symfony2

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

use EmailChecker\Constraints as EmailCheckerAssert;
use Symfony\Component\Validator\Constraints as Assert;

class User
{
    /**
     * @Assert\NotBlank
     * @EmailCheckerAssert\NotThrowawayEmail
     */
    protected $email;
}

License

EmailChecker is licensed under the MIT License — see the LICENSE file for details