silassiai/laravel-email-validation
Composer 安装命令:
composer require silassiai/laravel-email-validation
包简介
Validate your email with this email validation package on email filter, typos. dns and spoofing.
关键字:
README 文档
README
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,yahooandoutlook. Incoming email domains are compared against these to find typos. - Excluded domains — real, valid providers such as
ymailandmailboxthat 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:
- a length check — a difference of more than one character is never considered a typo;
- a character frequency comparison — at most 1 character may differ, or 2 for domain names longer than six characters;
- 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.
silassiai/laravel-email-validation 适用场景与选型建议
silassiai/laravel-email-validation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.48k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 08 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「email」 「validation」 「laravel」 「emailvalidation」 「email-validator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 silassiai/laravel-email-validation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 silassiai/laravel-email-validation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 silassiai/laravel-email-validation 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Adds request-parameter validation to the SLIM 3.x PHP framework
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
A jQuery augmented PHP library for creating and validating HTML forms
Simple ASCII output of array data
统计信息
- 总下载量: 3.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-02