PHPackages                             stymiee/email-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. stymiee/email-validator

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

stymiee/email-validator
=======================

A robust PHP 7.4+ email validation library that extends beyond basic validation with MX record checks, disposable email detection, and free email provider validation. Features include strict typing, custom validator support, internationalization (i18n), and an extensible architecture. Perfect for applications requiring thorough email verification with customizable validation rules.

2.1.0(1y ago)33487.3k↓27.8%9[1 issues](https://github.com/stymiee/email-validator/issues)1Apache-2.0PHPPHP &gt;=7.4CI failing

Since Aug 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/stymiee/email-validator)[ Packagist](https://packagist.org/packages/stymiee/email-validator)[ Docs](https://github.com/stymiee/email-validator)[ RSS](/packages/stymiee-email-validator/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (6)Versions (11)Used By (1)

[![Latest Stable Version](https://camo.githubusercontent.com/2107bd340905fe9745c4748fbded5c80703364d2cf49b929275e3163a16a2abb/68747470733a2f2f706f7365722e707567782e6f72672f7374796d6965652f656d61696c2d76616c696461746f722f762f737461626c652e737667)](https://packagist.org/packages/stymiee/email-validator)[![Total Downloads](https://camo.githubusercontent.com/b81f802e18ea9ea4e3874522c351905b5eba71d3a08db7cf0316d0d63a9c05b5/68747470733a2f2f706f7365722e707567782e6f72672f7374796d6965652f656d61696c2d76616c696461746f722f646f776e6c6f616473)](https://packagist.org/packages/stymiee/email-validator)[![Build](https://github.com/stymiee/email-validator/workflows/Build/badge.svg)](https://github.com/stymiee/email-validator/workflows/Build/badge.svg)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/14d145ec9fd90a977cbf392c49dc166e42c852beb467cf9ae807d3f324888c3f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7374796d6965652f656d61696c2d76616c696461746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/stymiee/email-validator/?branch=master)[![License](https://camo.githubusercontent.com/24e00309a423a497205fdbb529b34516699cb431eea23e1b4128d1baf9ef930f/68747470733a2f2f706f7365722e707567782e6f72672f7374796d6965652f656d61696c2d76616c696461746f722f6c6963656e7365)](https://packagist.org/packages/stymiee/email-validator)

PHP Email Validator (email-validator)
=====================================

[](#php-email-validator-email-validator)

The PHP Email Validator will validate an email address for all or some of the following conditions:

- is in a valid format (supports both RFC 5321 and RFC 5322)
- has configured MX records (optional)
- is not a disposable email address (optional)
- is not a free email account (optional)
- is not a banned email domain (optional)
- flag Gmail accounts that use the "plus trick" and return a sanitized email address

The Email Validator is configurable, so you have full control over how much validation will occur.

Requirements
------------

[](#requirements)

- PHP 7.4 or newer (v1.1.4 will work with PHP 7.2 or newer)

Installation
------------

[](#installation)

Simply add a dependency on `stymiee/email-validator` to your project's `composer.json` file if you use [Composer](https://getcomposer.org/) to manage the dependencies of your project.

Here is a minimal example of a `composer.json` file that just defines a dependency on PHP Simple Encryption:

```
{
    "require": {
        "stymiee/email-validator": "^2"
    }
}
```

Functional Description
----------------------

[](#functional-description)

The Email Validator library builds upon PHP's built in `filter_var($emailAddress, FILTER_VALIDATE_EMAIL);` by adding a default MX record check. It also offers additional validation against disposable email addresses, free email address providers, and a custom banned domain list.

### Validate MX

[](#validate-mx)

If `checkMxRecords` is set to `true` in the configuration (see below) the domain name will be validated to ensure it exists and has MX records configured. If the domain does not exist or no MX records exist the odds are the email address is not in use.

### Restrict Disposable Email Addresses

[](#restrict-disposable-email-addresses)

Many users who are abusing a system, or not using that system as intended, can use a disposable email service who provides a short-lived (approximately 10 minutes) email address to be used for registrations or user confirmations. If `checkDisposableEmail` is set to `true` in the configuration (see below) the domain name will be validated to ensure it is not associated with a disposable email address provider.

You can add you own domains to this list if you find the public list providers do not have one you have identified in their lists. Examples are provided in the `examples` directory which demonstrate how to do this.

### Restrict Free Email Address Providers

[](#restrict-free-email-address-providers)

Many users who are abusing a system, or not using that system as intended, can use a free email service who provides a free email address which is immediately available to be used for registrations or user confirmations. If `checkFreeEmail` is set to `true` in the configuration (see below) the domain name will be validated to ensure it is not associated with a free email address provider.

You can add you own domains to this list if you find the public list providers do not have one you have identified in their lists. Examples are provided in the `examples` directory which demonstrate how to do this.

### Restrict Banned Domains

[](#restrict-banned-domains)

If you have users from a domain abusing your system, or you have business rules that require the blocking of certain domains (i.e. public email providers like Gmail or Yahoo mail), you can block then by setting `checkBannedListedEmail`to `true` in the configuration (see below) and providing an array of banned domains. Examples are provided in the `examples` directory which demonstrate how to do this.

### Flag Gmail Addresses Using The "Plus Trick"

[](#flag-gmail-addresses-using-the-plus-trick)

Gmail offers the ability to create unique email addresses within a Google account by adding a `+` character and unique identifier after the username portion of the email address. If not explicitly checked for a user can create an unlimited amount of unique email addresses that all belong to the same account.

A special check can be performed when a Gmail account is used and a sanitized email address (e.g. one without the "plus trick") can be obtained and then checked for uniqueness in your system.

### Configuration

[](#configuration)

To configure the Email Validator you can pass an array with the follow parameters/values:

#### checkMxRecords

[](#checkmxrecords)

A boolean value that enables/disables MX record validation. Enabled by default.

#### checkBannedListedEmail

[](#checkbannedlistedemail)

A boolean value that enables/disables banned domain validation. Disabled by default.

#### checkDisposableEmail

[](#checkdisposableemail)

A boolean value that enables/disables disposable email address validation. Disabled by default.

#### checkFreeEmail

[](#checkfreeemail)

A boolean value that enables/disables free email address provider validation. Disabled by default.

#### localDisposableOnly

[](#localdisposableonly)

A boolean value that when set to `true` will not retrieve third party disposable email provider lists. Use this if you cache the list of providers locally which is useful when performance matters. Disabled by default.

#### LocalFreeOnly

[](#localfreeonly)

A boolean value that when set to `true` will not retrieve third party free email provider lists. Use this if you cache the list of providers locally which is useful when performance matters. Disabled by default.

#### bannedList

[](#bannedlist)

An array of domains that are not allowed to be used for email addresses.

#### disposableList

[](#disposablelist)

An array of domains that are suspected disposable email address providers.

#### freeList

[](#freelist)

An array of domains that are free email address providers.

**Example**

```
$config = [
    'checkMxRecords' => true,
    'checkBannedListedEmail' => true,
    'checkDisposableEmail' => true,
    'checkFreeEmail' => true,
    'bannedList' => $bannedDomainList,
    'disposableList' => $customDisposableEmailList,
    'freeList' => $customFreeEmailList,
];
$emailValidator = new EmailValidator($config);
```

### Example

[](#example)

```
