khanhicetea / fast-email-validator
A fast email validation library for PHP 7+
Requires
- php: ^7.0
Requires (Dev)
- mockery/mockery: ^0.9.9
- phpunit/phpunit: ^6.2
This package is auto-updated.
Last update: 2024-12-20 19:28:51 UTC
README
Fast email validation library for PHP 7+
Inspired by daveearley's Email-Validation-Tool
The aim of this library is to offer a more detailed email validation report than simply checking if an email is the valid format, and also to make it possible to easily add custom validations.
Currently this tool checks the following:
^ Data used for these checks can be found here
Why is it fast ?
Because we compile the text database to real PHP object, and use isset
function to check if a key existed.
Installation
composer require khanhicetea/fast-email-validator
Usage
Quick Start
// Include the composer autoloader require __DIR__ . '/vendor/autoload.php'; use FastEmailValidator\EmailAddress; use FastEmailValidator\EmailValidatorProvider; use FastEmailValidator\EmailValidator; $fastEmailValidator = new EmailValidator(); $provider = new EmailValidatorProvider(); $provider->registerValidator(new ValidFormatValidator()); $provider->registerValidator(new DisposableEmailValidator()); $provider->registerValidator(new EmailHostValidator()); $provider->registerValidator(new FreeEmailServiceValidator()); $provider->registerValidator(new MxRecordsValidator()); $provider->registerValidator(new RoleBasedEmailValidator()); $fastEmailValidator->registerEmailValidatorProvider($provider); $result = $fastEmailValidator->validate(new EmailAddress('hi@khanhicetea.com')); echo(json_encode($result));
Expected output:
{ "valid_format": true, "disposable_email_provider": false, "valid_host": true, "free_email_provider": false, "valid_mx_records": true, "role_or_business_email": true }
FAQ
Is this validation accurate?
No, none of these tests are 100% accurate. As with any email validation there will always be false positives & negatives. The only way to guarantee an email is valid is to send an email and solicit a response. However, this library is still useful for detecting disposable emails etc., and also acts as a good first line of defence.