PHP Classes

PHP Email Address Validator: Validate email addresses using checklists

Recommend this page to a friend!
  Info   View files Example   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 214 This week: 1All time: 8,319 This week: 560Up
Version License PHP version Categories
php-email-address-va 1.0.0Custom (specified...5Email, PHP 5, Validation
Description 

Author

This package can validate email addresses using checklists.

It takes a given email address and checks if it may be possible to deliver messages to that address by connecting to the SMTP server that handles messages for the email address domain.

The package also checks the email address first against whitelist and blacklists, as well check if the email address domain is in a list of disposable email address domains.

Picture of Enrico Sola
Name: Enrico Sola <contact>
Classes: 5 packages by
Country: Italy Italy
Age: 30
All time rank: 3209121 in Italy Italy
Week rank: 416 Up16 in Italy Italy Up

Example

<?php
require dirname(__FILE__) . '/php-email-address-validator.php';

use
PHPEmailAddressValidator\PHPEmailAddressValidator;

//Setting up lists.
PHPEmailAddressValidator::setWhiteListDatabasePath('whitelist.txt');
PHPEmailAddressValidator::setBlackListDatabasePath('blacklist.txt');
PHPEmailAddressValidator::setDisposableProvidersDatabasePath('disposable.txt');

$email = 'foo.bar@mail.com';
$disposable = 'foo.bar@yourdomain.com';

//Checking if the e-mail address is valid.
$result = PHPEmailAddressValidator::validateString($email);
echo
'Is a valid e-mail address? ' . ( $result === true ? 'Yes' : 'No' ) . PHP_EOL;

//Checking if the e-mail address is valid and existing.
$result = PHPEmailAddressValidator::validate($email);
echo
'Is a valid and existing e-mail address? ' . ( $result === true ? 'Yes' : 'No' ) . PHP_EOL;

//Checking if the e-mail address is accepted (its provider can be within the white list but not in the black list).
$result = PHPEmailAddressValidator::isTrustedProvider($disposable, false, true);
echo
'Is an accepted e-mail address? ' . ( $result === true ? 'Yes' : 'No' ) . PHP_EOL;

//Checking if the provider of the e-mail address is disposable or not.
$result = PHPEmailAddressValidator::isDisposableProvider($disposable);
echo
'Is a disposable e-mail address? ' . ( $result === true ? 'Yes' : 'No' ) . PHP_EOL;


Details

E-mail validator (PHP edition)

A very simple library that allows you to validate an e-mail address, check if it exists through online connection and check if the provider is a disposable one or not.

E-mail validation

String validation:

PHPEmailAddressValidator::validateString($email);

Complete validation:

PHPEmailAddressValidator::validate($email);

The complete validation will check address syntax first, after that will check for provider existence through DNS resolution and then will check if the given e-mail address exists.

E-mail provider check

Before using these methods you should set up dictionaries as following:

PHPEmailAddressValidator::setWhiteListDatabasePath('whitelist.txt'); PHPEmailAddressValidator::setBlackListDatabasePath('blacklist.txt'); PHPEmailAddressValidator::setDisposableProvidersDatabasePath('disposable.txt');

Check if the e-mail provider is accepted:

PHPEmailAddressValidator::isTrustedProvider($email, $disposableAllowed, $strict);

With accepted is meant that the provider is found within the given white list, if strict mode is not enabled, will be also checked if the provider is found within the black list, in this case will be returned "false". If the provider is checked using strict mode will be returned "true" only if it is found within the given white list. Both white list and black list must be plain text files and providers must be separated by a break line (\n).

Check if the e-mail provider is disposable:

PHPEmailAddressValidator::isDisposableProvider($disposable);

This method will check if the provider is included in the given list containing the disposable providers, a list with most common disposable providers is shipped with this library (kindly offered by @michenriksen). Disposable providers list must be plain text files and providers must be separated by a break line (\n).

Are you looking for the Node.js version? Give a look here.


  Files folder image Files  
File Role Description
Accessible without login Plain text file blacklist.txt Doc. Documentation
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file demo.php Example Example script
Accessible without login Plain text file disposable.txt Doc. Documentation
Accessible without login Plain text file LICENSE.md Lic. License text
Plain text file php-email-address-validator.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file whitelist.txt Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:214
This week:1
All time:8,319
This week:560Up
User Comments (1)
Thats a very good class ;-) Great job
5 years ago (José Filipe Lopes Santos)
80%StarStarStarStarStar