The Egulias/Email-Validator is a comprehensive library for validating emails in accord with several Request for Comments (RFCs). It provides adherence to standards such as RFC 5321, 5322, 6530, 6531, 6532, and 1035. An RFC is a type of publication from the Internet Engineering Task Force (IETF) and the Internet Society (ISOC), the principal technical development and standard-setting bodies for the internet. These standards ensure that email addresses are validated systematically and accurately, reducing the chances of spam or incorrect email input. The EmailValidator library offers robust functionalities for carrying out precise email validations, helping businesses maintain an authentic and quality email list.
To utilize the Egulias/Email-Validator, you first need to install it using Composer, a tool for dependency management in PHP. To do this, simply run the command
composer require egulias/email-validator in your project directory in the command line.
After installation, you will need to include the library and choose your validation strategy. Below is a basic example of how to use the library with the RFC validation:
<?php use Egulias\EmailValidator\EmailValidator; use Egulias\EmailValidator\Validation\RFCValidation; $validator = new EmailValidator(); $validator->isValid("email@example.com", new RFCValidation()); //true
The validation strategies available include RFCValidation, NoRFCWarningsValidation, DNSCheckValidation, MultipleValidationWithAnd, MessageIDValidation, and even an option to create your own custom validation.
For example, to include the DNSCheckValidation alongside the RFCValidation, you can do something like this:
<?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() ]); $validator->isValid("firstname.lastname@example.org", $multipleValidations); //true
Detailed documentation for the Egulias/Email-Validator can be found directly on its GitHub repository, under the URL https://github.com/egulias/EmailValidator.git. The GitHub documentation provides a comprehensive walkthrough of installation procedures, available validations, strategies for combining validations, and more. It's also possible to contribute to the project following the given contribution guide. The license information along with other contributors can also be found in the project repository.