silassiai/laravel-email-validation

Validate your email with this email validation package on email filter, typos. dns and spoofing.

Maintainers

Package info

github.com/Silassiai/laravel-email-validation

pkg:composer/silassiai/laravel-email-validation

Transparency log

Statistics

Installs: 3 550

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v2.0.0 2026-07-02 11:43 UTC

README

Tests Latest Version on Packagist Total Downloads License

Catch email domain typos before they end up in your database.

When a user signs up with silas@gmial.com, they almost certainly meant silas@gmail.com — and every mail you send to the typoed address will bounce. This package detects typos in the domain part of an email address by comparing it against a list of known mail providers, and suggests the domain the user most likely meant. Perfect for a "Did you mean silas@gmail.com?" prompt on your registration or checkout form.

Features

  • Typo detection — detects swapped, missing or extra characters in mail provider domains (gmial.com, hotmal.com, gmaill.com, …) and returns the most likely intended domain.
  • Domain validation — check whether an email uses a known mail provider domain.
  • False-positive protection — real providers that look like typos of bigger ones (e.g. ymail.com, mailbox.org) are listed as "excluded" domains, so they are recognized as valid and never flagged.
  • Zero setup, fast — the provider lists ship with the package as plain PHP arrays. No database, no cache, no seeding; validating millions of addresses is pure in-memory work.
  • Extendable — add your own provider domains through a config file.

Planned for future versions: DNS record validation and spoofing checks.

Requirements

Dependency Supported versions
PHP 8.2 – 8.4
Laravel 12.x, 13.x

Only actively supported Laravel versions are supported. No database or cache is needed: the provider lists ship with the package.

Installation

Install the package via composer:

composer require silassiai/laravel-email-validation

The service provider is auto-discovered by Laravel, so there is nothing to register manually — you can start validating right away. Updates to the built-in provider lists arrive automatically with composer update.

Configuration

Want to validate against your own provider domains as well? Publish the config file:

php artisan vendor:publish --tag=email-validation-config

Then add your domains in config/email-validation.php. They are merged with the built-in lists:

return [
    // Checked for typos, just like the built-in providers
    'additional_popular' => [
        'snelmail' => ['nl'],
    ],

    // Recognized as valid, but never reported as a typo of another provider
    'additional_excluded' => [
        'mijnbedrijf' => ['nl'],
    ],
];

Usage

Typo validation

hasTypo() returns the domain the user probably meant, or null when no typo was found:

use Silassiai\LaravelEmailValidation\Facades\EmailValidationFacade;

EmailValidationFacade::for('silas@gmial.com')->hasTypo();   // 'gmail.com'
EmailValidationFacade::for('silas@hotmal.nl')->hasTypo();   // 'hotmail.nl'
EmailValidationFacade::for('silas@gmail.com')->hasTypo();   // null (valid address)
EmailValidationFacade::for('silas@mycompany.com')->hasTypo(); // null (unknown domain, no suggestion)

When the domain name matches a provider but the extension isn't in the provider's list of known extensions, only the domain name is returned:

EmailValidationFacade::for('silas@gmial.xyz')->hasTypo();   // 'gmail'

A typical "did you mean" flow in a controller:

if ($suggestion = EmailValidationFacade::for($request->email)->hasTypo()) {
    $localPart = Str::before($request->email, '@');

    return back()->withInput()->with(
        'email_suggestion',
        "Did you mean {$localPart}@{$suggestion}?"
    );
}

Domain validation

hasValidDomain() checks whether the domain name belongs to a known mail provider:

EmailValidationFacade::for('silas@gmail.com')->hasValidDomain();     // true
EmailValidationFacade::for('silas@mycompany.com')->hasValidDomain(); // false

How it works

The package ships with two curated domain lists (see Silassiai\LaravelEmailValidation\Data\MailProviderDomains):

  • Popular domains — well-known providers such as gmail, hotmail, yahoo and outlook. Incoming email domains are compared against these to find typos.
  • Excluded domains — real, valid providers such as ymail and mailbox that closely resemble a popular domain. These are recognized as valid and are never reported as a typo of another provider.

The domain part of the email is parsed from the right: the extension is the last label — or the last two labels for known two-label suffixes such as co.uk and com.au — and the domain name is the label directly in front of it. Subdomains are ignored, so silas@mail.mycompany.nl is treated as domain name mycompany with extension nl and does not collide with the mail provider.

The two-label suffixes are a curated subset of the Public Suffix List, covering the countries where the built-in providers operate (see SECOND_LEVEL_SUFFIXES in Silassiai\LaravelEmailValidation\Validation\Email). The full list — thousands of entries, including internationalized suffixes — is intentionally not bundled: for a suffix that is not in the subset (say com.gy), the parser falls back to treating the last label as the extension. That misparse is harmless: the resulting domain name (com, net, org, …) never matches or resembles a provider, so no false typo is ever reported — at worst a typo in such a domain goes undetected.

For the typo check itself, the domain name is compared against each popular provider using:

  1. a length check — a difference of more than one character is never considered a typo;
  2. a character frequency comparison — at most 1 character may differ, or 2 for domain names longer than six characters;
  3. a first-characters check — real typos rarely start completely differently, so at least part of the first three characters must line up.

Testing

composer test         # run the PHPUnit test suite
composer analyse      # run PHPStan static analysis (level: max)
composer format       # fix code style with Laravel Pint
composer format:test  # check code style without fixing

The test suite runs against PHP 8.2 – 8.4 and Laravel 12 – 13 on every push via GitHub Actions, along with PHPStan at the maximum level and a Pint code style check.

Upgrading

Please see UPGRADING for details.

Changelog

Please see CHANGELOG for more information what has changed recently.

Credits

License

The MIT License. Please see License for more information.