Guide · Open source
How to use EmailValidator: install and validate emails in PHP
Updated · written with AI from the project's own documentation and checked against our catalogue data
EmailValidator is a MIT-licensed PHP library for checking whether an email address follows the format rules in several RFC standards. You choose a validation strategy, such as a standard format check or a DNS check for mail servers on the domain, and the library returns true or false. This guide covers installation with Composer, the available validation strategies, how to combine them, and what the DNS check does and does not prove.
Quick start
- 1Check PHP and Composer. Confirm you run PHP 8.1 or later and have Composer installed. Add the PHP Intl extension if you plan to use DNS or spoof checks.
- 2Install the package. Run composer require egulias/email-validator in your project directory.
- 3Create a validator. In your PHP code, import EmailValidator and instantiate it with new EmailValidator().
- 4Pick a strategy. Pass RFCValidation or another strategy from the README list as the second argument to isValid().
- 5Combine checks if needed. Wrap RFCValidation and DNSCheckValidation in MultipleValidationWithAnd to require both.
- 6Handle the result. Use the true or false return value in your sign-up or contact form logic.
Check the requirements before you install
EmailValidator is written for PHP and installed with Composer. The README lists PHP 8.1 as a requirement, so projects on older PHP versions will need a different approach.
If you plan to use the Spoofchecking or DNSCheckValidation strategies, your PHP system also needs the PHP Internationalization Libraries, also known as PHP Intl.
- PHP 8.1 or later
- Composer, for installation
- PHP Intl extension, only if you use SpoofCheckValidation or DNSCheckValidation
Install EmailValidator with Composer
Run the Composer command below in your project directory to add the library as a dependency.
composer require egulias/email-validatorRun your first email check
Create an EmailValidator object and pass an address along with a validation strategy. The README's basic example uses RFCValidation, and the call returns true for a valid address.
<?php
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\RFCValidation;
$validator = new EmailValidator();
$validator->isValid("example@example.com", new RFCValidation()); //trueChoose a validation strategy
You must pick at least one strategy for each check. The README lists these built-in options:
- RFCValidation: standard RFC-like email validation.
- NoRFCWarningsValidation: RFC-like validation that fails when warnings are found. Warnings are deviations from the RFC that a broader interpretation accepts.
- DNSCheckValidation: checks whether DNS records show that the domain accepts email. The README states this does not mean the specific email exists.
- MultipleValidationWithAnd: runs several validations and combines results with a logical AND (&&).
- MessageIDValidation: follows RFC 2822 for message-id fields, which differ in the domain part.
- SpoofCheckValidation (additional, not from the RFCs): flags multi-UTF-8 characters that can signal an erroneous email name.
Combine a format check with a DNS check
To require both a format check and a domain check, wrap them in MultipleValidationWithAnd. The README's example checks example@ietf.org, which passes because ietf.org has MX records signalling a mail server.
<?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("example@ietf.org", $multipleValidations); //trueUnderstand what the check can and cannot prove
A DNS check only shows that the domain appears to accept email. It does not confirm that a specific mailbox exists. If you need to know that an address is real, the README gives no method for that, so you will need to handle it outside this library, for example with a confirmation email.
You can also extend the library by implementing the EmailValidation interface and passing your own validation to isValid().
What people use it for
- Validating email fields on a sign-up form before saving the account
- Checking contact form submissions for well-formed sender addresses
- Requiring that an address's domain has mail servers using a DNS check
- Choosing strict or lenient rules through NoRFCWarningsValidation or RFCValidation
Frequently asked questions
How do I install egulias EmailValidator?
Run composer require egulias/email-validator in your project directory. The library requires PHP 8.1 and Composer, as listed in the README.
What PHP version does EmailValidator need?
The README lists PHP 8.1 as a requirement. Projects running PHP versions below 8.1 are not covered by this library's stated requirements.
Is EmailValidator free to use?
Yes, it is released under the MIT License, as stated in the README. Check the license file in the repository for the full terms.
Does EmailValidator confirm that an email address exists?
No. The DNSCheckValidation strategy only checks for DNS records that show the domain accepts email. The README says this does not establish that the specific address exists.
Can I use EmailValidator outside PHP?
No. The library is written for PHP and installed through Composer, so non-PHP projects should use a tool written for their own language.
What is the alternative to EmailValidator in PHP?
Comparable options named in the analysis include PHP's built-in filter_var with FILTER_VALIDATE_EMAIL, the email constraint in Symfony Validator, and forks or wrappers of this library in other PHP frameworks.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Use EmailValidator if you build PHP applications and want format checks that go beyond a simple regex, optionally combined with a domain DNS check. Pick something else if your project is not PHP, runs PHP below 8.1, or needs proof that a mailbox exists, since the README says the library cannot establish that.
Install options & downloads