EmailValidator README

The project's README from github.com/egulias/EmailValidator. As one markdown file: README.md.

EmailValidator

Build Status Quality Badge Test Coverage Latest Release

A library for validating emails against several RFC.

Supported RFCs

This library aims to support RFCs:

Supported versions

Version Released EOL Only critical bug fixes Full
v4.x 2023/01/07 - X X
v3.x 2020/12/29 YES
v2.1.x 2016/05/16 YES
v1.2 2013/19/05 YES

Requirements

Note: PHP version upgrades will happen to accomodate to the pace of major frameworks. Minor versions bumps will go via minor versions of this library (i.e: PHP7.3 -> v3.x+1). Major versions will go with major versions of the library

Installation

Run the command below to install via Composer

composer require egulias/email-validator

Getting Started

EmailValidator requires you to decide which (or combination of them) validation/s strategy/ies you'd like to follow for each validation.

A basic example with the RFC validation

<?php

use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\RFCValidation;

$validator = new EmailValidator();
$validator->isValid("[email protected]", new RFCValidation()); //true

Available validations

  1. RFCValidation: Standard RFC-like email validation.
  2. NoRFCWarningsValidation: RFC-like validation that will fail when warnings* are found.
  3. DNSCheckValidation: Will check if there are DNS records that signal that the server accepts emails. This does not entail that the email exists.
  4. MultipleValidationWithAnd: It is a validation that operates over other validations performing a logical and (&&) over the result of each validation.
  5. MessageIDValidation: Follows RFC2822 for message-id to validate that field, that has some differences in the domain part.
  6. Your own validation: You can extend the library behaviour by implementing your own validations.

*warnings: Warnings are deviations from the RFC that in a broader interpretation are accepted.

<?php

use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\DNSCheckValidation;
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
use Egulias\EmailValidator\Validation\RFCValidation;

$validator = new EmailValidator();
$multipleValidations = new MultipleValidationWithAnd([
    new RFCValidation(),
    new DNSCheckValidation()
]);
//ietf.org has MX records signaling a server with email capabilities
$validator->isValid("[email protected]", $multipleValidations); //true

Additional validations

Validations not present in the RFCs

  1. SpoofCheckValidation: Will check for multi-utf-8 chars that can signal an erroneous email name.

How to extend

It's easy! You just need to implement EmailValidation and you can use your own validation.

Contributing

Please follow the Contribution guide. Is short and simple and will help a lot.

Other Contributors

(You can find current contributors here)

As this is a port from another library and work, here are other people related to the previous one:

License

Released under the MIT License attached with this code.

EmailValidator (egulias/EmailValidator)

Searching Database…

这是干什么的?一个 PHP 库,用来按照多个 RFC(5321、5322、6530、6531、6532 和 1035)对电子邮件地址做校验。
它是一个独立的应用,还是引入到我项目里的代码?它是一个库,不是应用:你在 PHP 项目中引入它,然后在自己的代码里调用它的校验类。
怎么把它加到我的 PHP 项目里?用 Composer 安装(README 里给了 require 命令),然后为每次检查选择使用哪种校验策略,或者几种策略组合使用。
环境需要满足什么条件,它的所有检查才能正常工作?需要 PHP 8.1 或更高版本,外加 Composer。Spoof checking 和 DNSCheckValidation 还需要 PHP 国际化扩展(PHP Intl)。
如果 DNS 检查通过了,就能确定这个邮箱真的存在吗?不能——DNSCheckValidation 只是查找表明服务器接收邮件的 DNS 记录;检查通过并不代表这个地址真的存在。
它自带哪些校验策略?内置选项有:RFCValidation(标准 RFC 式检查)、NoRFCWarningsValidation(发现警告即判定失败)、DNSCheckValidation、MessageIDValidation(针对 RFC2822 的 message-id 字段)、SpoofCheckValidation(标记可疑的多 UTF-8 字符),以及把其他校验按逻辑与组合起来的 MultipleValidationWithAnd。
可以把多种校验组合使用,或者自己写校验吗?可以。MultipleValidationWithAnd 会包装其他校验,只有全部通过才算通过;你还可以实现 EmailValidation 接口,用自己的规则来扩展这个库。
它能处理含有非 ASCII 字符的国际化邮箱地址吗?能——这个库明确支持覆盖国际化地址的 RFC 6530、6531 和 6532,而且 SpoofCheckValidation 可以标记出可疑的多 UTF-8 字符名称,提示邮箱名称可能有误。
我该用哪个版本?这个项目还在维护吗?请用 2023 年 1 月发布的 v4.x,这是目前完全受支持的版本线。v3.x、v2.1.x 和 v1.2 已停止维护,并且 PHP 版本要求会随库版本升级而逐步提高。
Creator
egulias
Size
0.7 MB
Stars
11.6K
Age
13y
Commits · 90 Days