PHP Classes

How to use a PHP email validation class that can invalidate email addresses that use lists of invalid domains using the package Easy Email Validator: Validate email addresses using domain lists

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-11-08 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
easyemailvalidator 1.0.0MIT/X Consortium ...8Email, Web services, Validation, PHP 8
Description 

Author

This package can validate email addresses using domain lists.

It provides a class that can take a list of email addresses and validate it using lists of domains that may be considered invalid.

The class can use a provider object that provides the list of invalid domains.

It also allows you to strictly control which domains are permitted by defining one or multiple allowed domains, making it easy to restrict emails to your organization or trusted providers only.

Innovation Award
PHP Programming Innovation award nominee
November 2025
Number 8
Validating email addresses is often an important task that sites and applications need to perform to avoid sending messages to users that provide email addresses that are invalid, in some cases due to user mistakes or users that do not want to provide real email addresses.

In some cases, users provide email addresses that are disposable after a while. The domains used by these disposable email addresses are known. New disposable email addresses continue to be created.

This package can validate email addresses using provider classes that can be updated by retrieving the disposable email addresses from a provider that continues to update the list of disposable email addresses domains.

Manuel Lemos
Picture of Pierre S
  Performance   Level  
Name: Pierre S <contact>
Classes: 1 package by
Country: France France
Age: ???
All time rank: Not yet ranked
Week rank: Not yet ranked
Innovation award
Innovation award
Nominee: 1x

Instructions

Documentation

EasyEmailValidator

A lightweight PHP package to validate email addresses against allowed and denied domain lists.

Installation

Add the package to your project with Composer:

composer require auvernhat/easyemailvalidator

Usage

use Auvernhat\EasyEmailValidator\EasyValidator;

$validator = new EasyValidator();

// Validate a single email address
$isValid = $validator->validate('[email protected]'); // true or false

// Validate multiple email addresses
$allValid = $validator->validateMultiple([
    '[email protected]',
    '[email protected]'
]); // true if all are valid, false otherwise

Providers

EasyEmailValidator supports multiple providers to fetch lists of allowed or denied email domains. A provider is a PHP class that extends the abstract class ProviderAbstract and implements two methods:

  • `getAllowDomains(): array` ? returns an array of allowed domains (can be empty if not used).
  • `getDenyDomains(): array` ? returns an array of denied domains.

Available Providers

Several providers are included by default:

How to Use a Provider

You can specify the provider to use when creating the validator:

use Auvernhat\EasyEmailValidator\EasyValidator;
use Auvernhat\EasyEmailValidator\Providers\AdamLovingProvider;

$validator = new EasyValidator(new AdamLovingProvider());
$isValid = $validator->validate('[email protected]');

If you don't specify a provider, the default is DisposableProvider:

$validator = new EasyValidator(); // Uses DisposableProvider by default

How to Create Your Own Provider

To add your own provider, create a new class in src/Providers/ that extends ProviderAbstract and implements the required methods:

use Auvernhat\EasyEmailValidator\Providers\ProviderAbstract;

class MyCustomProvider extends ProviderAbstract
{
    public function getAllowDomains(): array
    {
        // Return your list of allowed domains
        return ['example.com'];
        // Return nothing if you only want a deny list
        return [];
    }

    public function getDenyDomains(): array
    {
        // Return your list of denied domains
        return ['tempmail.com', 'mailinator.com'];
        // Return nothing if you only want an allow list
        return [];
    }
}

Example: Allow Only Your Company's Emails

You can create a custom provider that only allows emails from your own company domain. For example, to only accept @mycompany.com addresses:

use Auvernhat\EasyEmailValidator\Providers\ProviderAbstract;

class MyCustomProvider extends ProviderAbstract
{
    public function getAllowDomains(): array
    {
        return ['mycompany.com'];
    }

    public function getDenyDomains(): array
    {
        return [];
    }
}

$validator = new EasyValidator(new MyCustomProvider);

$res = $validator->validate("[email protected]");
// returns false
$res = $validator->validate("[email protected]");
// returns true

This is useful if you want to restrict access or registration to your own organization only.

Simple, fast, and effective for filtering disposable emails!


  Files folder image Files (11)  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (1 file, 1 directory)
Files folder imagetests (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (11)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (11)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file ci.yml Data Auxiliary data

  Files folder image Files (11)  /  src  
File Role Description
Files folder imageProviders (4 files)
  Plain text file EasyValidator.php Class Class source

  Files folder image Files (11)  /  src  /  Providers  
File Role Description
  Plain text file AdamLovingProvider.php Class Class source
  Plain text file AmieiroProvider.php Class Class source
  Plain text file DisposableProvider.php Class Class source
  Plain text file ProviderAbstract.php Class Class source

  Files folder image Files (11)  /  tests  
File Role Description
  Plain text file EasyValidatorTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0