PHPackages                             plin-code/laravel-email-fixer - 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. plin-code/laravel-email-fixer

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

plin-code/laravel-email-fixer
=============================

Sanitize, normalize and auto-correct malformed email addresses before validation in Laravel

v1.0.0(1mo ago)11↑2900%MITPHPPHP ^8.3CI passing

Since Mar 28Pushed 1mo agoCompare

[ Source](https://github.com/plin-code/laravel-email-fixer)[ Packagist](https://packagist.org/packages/plin-code/laravel-email-fixer)[ Docs](https://github.com/plin-code/laravel-email-fixer)[ GitHub Sponsors]()[ RSS](/packages/plin-code-laravel-email-fixer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (15)Versions (2)Used By (0)

Laravel Email Fixer
===================

[](#laravel-email-fixer)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e8c1c0c2628dd50c73c5d5df4f2cc30ba0172906ba5eba20f752d584d392e399/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706c696e2d636f64652f6c61726176656c2d656d61696c2d66697865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/plin-code/laravel-email-fixer)[![GitHub Tests Action Status](https://camo.githubusercontent.com/ce5a9eebed77930ff4ab0b37ca2219b163b0346be82778fd3d9f07f6bd3d6202/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706c696e2d636f64652f6c61726176656c2d656d61696c2d66697865722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/plin-code/laravel-email-fixer/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/4118a02036470fdd5a7d4ba416e9f8df54ace1ee8d216223889fec3548453c7e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706c696e2d636f64652f6c61726176656c2d656d61696c2d66697865722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/plin-code/laravel-email-fixer/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/349758d087a7fe96beeb08ed61247c8cc24271e34460ee06487a1f2a4e8e7963/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706c696e2d636f64652f6c61726176656c2d656d61696c2d66697865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/plin-code/laravel-email-fixer)

Sanitize, normalize and auto-correct malformed email addresses in Laravel. Handles common typos from web forms, CSV imports, and mobile keyboards, including locale-specific issues like the Italian `ò` → `@` keyboard quirk.

The Problem
-----------

[](#the-problem)

Users constantly submit broken email addresses. Typos, missing `@` signs, incomplete domains, trailing dots, angle brackets from copy-paste, commas instead of dots. Every registration form, every CSV import, every contact form collects these. Most apps just reject them and lose the user.

**Laravel Email Fixer** automatically repairs these emails before validation, so your users don't bounce off your forms.

### What It Fixes

[](#what-it-fixes)

InputOutputFixer` user@gmail.com ``user@gmail.com`TrimWhitespace```user@gmail.com`StripAngleBrackets`user@gmail,com``user@gmail.com`CommaToDot`usergmail.com``user@gmail.com`InsertMissingAt`user@gmail``user@gmail.com`CompleteDomain`user@gmailcom``user@gmail.com`FixDomainSeparator`user.@gmail.com``user@gmail.com`CleanLocalPart`user@gmail.com.``user@gmail.com`CleanTrailingDots`User@Gmail.COM``user@gmail.com`Lowercase`user@gmail.com§``user@gmail.com`StripNonAsciiTrailing`userògmail.com``user@gmail.com`ItalianKeyboard (locale: `it`)Installation
------------

[](#installation)

```
composer require plin-code/laravel-email-fixer
```

Optionally publish the config file:

```
php artisan vendor:publish --tag="laravel-email-fixer-config"
```

Quick Start
-----------

[](#quick-start)

### Using the Facade

[](#using-the-facade)

```
use PlinCode\LaravelEmailFixer\Facades\EmailFixer;

// Fix a single email
$fixed = EmailFixer::fix('user@gmail,com');
// "user@gmail.com"

// Fix or get null if unfixable
$fixed = EmailFixer::fixOrNull('not-an-email');
// null

// Check if input is garbage before attempting a fix
$isGarbage = EmailFixer::isGarbage('asdf');
// true

// Get a detailed report
$report = EmailFixer::diagnose('usergmail.com');
// $report->original       → "usergmail.com"
// $report->fixed          → "user@gmail.com"
// $report->appliedFixers  → ["InsertMissingAt"]
// $report->isValid        → true
// $report->wasModified    → true

// Batch processing
$reports = EmailFixer::fixMany([
    'user@gmail,com',
    'admin@yahoo',
    'info@hotmail.com.',
]);
```

### Using the Validation Rule

[](#using-the-validation-rule)

Apply the `SanitizedEmail` rule to auto-fix and validate email fields in one step. The fixed value is automatically merged back into the request.

```
use PlinCode\LaravelEmailFixer\Rules\SanitizedEmail;

public function rules(): array
{
    return [
        'email' => ['required', new SanitizedEmail],
    ];
}
```

With options:

```
// Enable strict RFC validation and garbage rejection
new SanitizedEmail(strict: true, rejectGarbage: true)

// With Italian locale
new SanitizedEmail(locale: 'it')
```

### Using the Middleware

[](#using-the-middleware)

Register the `SanitizeEmails` middleware to automatically fix all email fields in incoming requests before they reach your controllers.

```
use PlinCode\LaravelEmailFixer\Middleware\SanitizeEmails;

// In a route group
Route::middleware(SanitizeEmails::class)->group(function () {
    Route::post('/register', [RegisterController::class, 'store']);
});

// Or globally in bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->append(SanitizeEmails::class);
})
```

By default, the middleware targets fields matching these patterns: `email`, `*_email`, `email_*`, `*email*`. You can customize this in the config file.

Use Cases
---------

[](#use-cases)

### Registration and Login Forms

[](#registration-and-login-forms)

The most common scenario. Users mistype their email on signup, never receive the confirmation, and leave. With Email Fixer, most typos are silently corrected.

```
// In your registration form request
public function rules(): array
{
    return [
        'email' => ['required', new SanitizedEmail(rejectGarbage: true), 'unique:users'],
    ];
}
```

### CSV/Bulk Import

[](#csvbulk-import)

When importing contacts or users from spreadsheets, email quality is often poor. Use `fixMany()` to clean them in bulk and `diagnose()` to flag the ones that could not be repaired.

```
use PlinCode\LaravelEmailFixer\Facades\EmailFixer;

$emails = array_column($rows, 'email');

$reports = EmailFixer::fixMany($emails);

foreach ($reports as $index => $report) {
    if ($report->isValid) {
        $rows[$index]['email'] = $report->fixed;
    } else {
        $failed[] = $rows[$index]; // flag for manual review
    }
}
```

### Italian (or Locale-Specific) Users

[](#italian-or-locale-specific-users)

Italian keyboards place the `ò` key right next to the `@` key, causing a very common typo. Enable the Italian locale to handle this automatically, along with local domain shortcuts like `libero` → `libero.it`.

```
// Via config (config/email-fixer.php)
'locale' => 'it',

// Or at runtime
$fixer = EmailFixer::locale('it');
$fixer->fix('mrossiòlibero'); // "mrossi@libero.it"
```

### API Input Sanitization

[](#api-input-sanitization)

Use the middleware on your API routes to transparently sanitize emails before any validation or processing takes place.

```
Route::middleware(SanitizeEmails::class)
    ->prefix('api')
    ->group(function () {
        Route::post('/subscribe', [NewsletterController::class, 'subscribe']);
        Route::post('/invite', [InviteController::class, 'send']);
    });
```

### Auditing and Debugging

[](#auditing-and-debugging)

Use `diagnose()` to understand exactly what was changed and why, useful for logging or admin dashboards.

```
$report = EmailFixer::diagnose('  USER@Gmail,COM.  ');

logger()->info('Email fixed', [
    'original' => $report->original,
    'fixed' => $report->fixed,
    'fixers' => $report->appliedFixers,
    'was_modified' => $report->wasModified,
]);
```

Configuration
-------------

[](#configuration)

The published config file (`config/email-fixer.php`) allows you to customize:

```
return [
    // Locale preset: 'it' or null
    'locale' => null,

    // Domain shortcuts (expanded by CompleteDomain fixer)
    'domains' => [
        'gmail'       => 'gmail.com',
        'hotmail'     => 'hotmail.com',
        'yahoo'       => 'yahoo.com',
        'outlook'     => 'outlook.com',
        'icloud'      => 'icloud.com',
        'live'        => 'live.com',
        'proton'      => 'proton.me',
        'protonmail'  => 'protonmail.com',
    ],

    // Custom fixer pipeline (null = default pipeline)
    'fixers' => null,

    // Middleware field patterns
    'middleware' => [
        'fields' => ['email', '*_email', 'email_*', '*email*'],
    ],

    // Garbage detection thresholds
    'garbage' => [
        'min_length' => 3,
        'require_at' => true,
        'require_dot_in_domain' => true,
    ],
];
```

### Custom Fixer Pipeline

[](#custom-fixer-pipeline)

You can define your own fixer order or add custom fixers:

```
'fixers' => [
    \PlinCode\LaravelEmailFixer\Fixers\TrimWhitespace::class,
    \PlinCode\LaravelEmailFixer\Fixers\Lowercase::class,
    \App\EmailFixers\MyCustomFixer::class,
],
```

Custom fixers must implement `PlinCode\LaravelEmailFixer\Contracts\FixerInterface`:

```
use PlinCode\LaravelEmailFixer\Contracts\FixerInterface;

class MyCustomFixer implements FixerInterface
{
    public function fix(string $email): string
    {
        // your logic here
        return $email;
    }

    public function name(): string
    {
        return 'MyCustomFixer';
    }
}
```

Standalone Usage
----------------

[](#standalone-usage)

You can use Email Fixer outside of Laravel:

```
use PlinCode\LaravelEmailFixer\EmailFixer;

$fixer = EmailFixer::defaults(
    domainMap: ['gmail' => 'gmail.com', 'yahoo' => 'yahoo.com'],
);

$fixed = $fixer->fix('user@gmail');
// "user@gmail.com"
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Daniele Barbaro](https://github.com/plin-code)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance90

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

46d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7653cedfb706bdbaceab17cb57fa55d5e2744faeb722cfc1e2af8c3fd88f13ef?d=identicon)[danielebarbaro](/maintainers/danielebarbaro)

---

Top Contributors

[![danielebarbaro](https://avatars.githubusercontent.com/u/4376886?v=4)](https://github.com/danielebarbaro "danielebarbaro (16 commits)")

---

Tags

emailhacktoberfestimportlaravelrulessanitizervalidationnormalizelaravelvalidationemailtyposanitizecsv-importplin-codeautocorrectlaravel-email-fixer

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/plin-code-laravel-email-fixer/health.svg)

```
[![Health](https://phpackages.com/badges/plin-code-laravel-email-fixer/health.svg)](https://phpackages.com/packages/plin-code-laravel-email-fixer)
```

###  Alternatives

[propaganistas/laravel-disposable-email

Disposable email validator

5762.6M6](/packages/propaganistas-laravel-disposable-email)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
