auvernhat/easyemailvalidator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

auvernhat/easyemailvalidator

最新稳定版本:1.1.0

Composer 安装命令:

composer require auvernhat/easyemailvalidator

包简介

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

README 文档

README

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('test@gmail.com'); // true or false

// Validate multiple email addresses
$allValid = $validator->validateMultiple([
    'test@gmail.com',
    'test@outlook.com'
]); // 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('test@gmail.com');

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("test@gmail.com");
// returns false
$res = $validator->validate("test@mycompany.com");
// 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!

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固