All Projects → daveearley → Email Validation Tool

daveearley / Email Validation Tool

Licence: mit
An easy to use, accurate-ish & extensible email validation library for PHP 7+ 📧

Projects that are alternatives of or similar to Email Validation Tool

NeverBounceAPI-PHP
This package provides convenient methods to integrate the NeverBounce API into your project.
Stars: ✭ 22 (-91.2%)
Mutual labels:  email, email-validation
EmailValidationPascal
Simple Class for Validating Email Address Syntax in Pascal/Delphi
Stars: ✭ 32 (-87.2%)
Mutual labels:  email, email-validation
Mailchecker
📫 Cross-language temporary (disposable/throwaway) email detection library. Covers 33600 fake email providers.
Stars: ✭ 1,252 (+400.8%)
Mutual labels:  email, email-validation
email-checker
Provides email verification on the go.
Stars: ✭ 116 (-53.6%)
Mutual labels:  email, email-validation
Check If Email Exists
Check if an email address exists without sending any email, written in Rust.
Stars: ✭ 497 (+98.8%)
Mutual labels:  email, email-validation
Truemail
🚀 Configurable framework agnostic plain Ruby 📨 email validator/verifier. Verify email via Regex, DNS and SMTP. Be sure that email address valid and exists.
Stars: ✭ 717 (+186.8%)
Mutual labels:  email, email-validation
Emailvalidation
A simple (but correct) .NET class for validating email addresses
Stars: ✭ 171 (-31.6%)
Mutual labels:  email, email-validation
Drymail
Makes sending emails easy and DRY — For Python 3.
Stars: ✭ 218 (-12.8%)
Mutual labels:  email
Oblivion
Data leak checker & OSINT Tool
Stars: ✭ 237 (-5.2%)
Mutual labels:  email
Sendgrid Nodejs
The Official Twilio SendGrid Led, Community Driven Node.js API Library
Stars: ✭ 2,543 (+917.2%)
Mutual labels:  email
Iky
OSINT Project
Stars: ✭ 203 (-18.8%)
Mutual labels:  email
Vmime
VMime Mail Library
Stars: ✭ 218 (-12.8%)
Mutual labels:  email
Mailu
Insular email distribution - mail server as Docker images
Stars: ✭ 3,151 (+1160.4%)
Mutual labels:  email
Forwardemail.net
The best free email forwarding for custom domains (Web Server)
Stars: ✭ 211 (-15.6%)
Mutual labels:  email
React Email Editor
Drag-n-Drop Email Editor Component for React.js
Stars: ✭ 3,131 (+1152.4%)
Mutual labels:  email
Nodemailer
✉️ Send e-mails with Node.JS – easy as cake!
Stars: ✭ 14,354 (+5641.6%)
Mutual labels:  email
Meli
🐝 experimental terminal mail client, mirror of https://git.meli.delivery/meli/meli.git https://crates.io/crates/meli
Stars: ✭ 242 (-3.2%)
Mutual labels:  email
Mailyak
An elegant MIME/SMTP email library with support for attachments
Stars: ✭ 244 (-2.4%)
Mutual labels:  email
Magento 2 Smtp
Magento 2 SMTP Extension helps the owner of store simply install SMTP (Simple Mail Transfer Protocol) server which transmits the messages into codes or numbers.
Stars: ✭ 228 (-8.8%)
Mutual labels:  email
Juice
Juice inlines CSS stylesheets into your HTML source.
Stars: ✭ 2,683 (+973.2%)
Mutual labels:  email

PHP Email Validation Tool

codecov Build Status Code Climate

An extensible email validation library for PHP 7+

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:

Validation Description
MX records Checks if the email's domain has valid MX records
Valid format Validates e-mail addresses against the syntax in RFC 822, with the exceptions that comments and whitespace folding and dotless domain names are not supported (as it uses PHP's filter_var()).
Email Host Checks if the email's host (e.g gmail.com) is reachable
Role/Business Email^ Checks if the email is a role/business based email (e.g [email protected]).
Disposable email provider^ Checks if the email is a disposable email (e.g [email protected]).
Free email provider^ Checks if the email is a free email (e.g [email protected]).
Misspelled Email ^ Checks the email for possible typos and returns a suggested correction (e.g [email protected] -> [email protected]).

^ Data used for these checks can be found here

Installation

composer require daveearley/daves-email-validation-tool

Usage

Quick Start

// Include the composer autoloader
require __DIR__ . '/vendor/autoload.php';

$validator = EmailValidation\EmailValidatorFactory::create('[email protected]');

$jsonResult = $validator->getValidationResults()->asJson();
$arrayResult = $validator->getValidationResults()->asArray();

echo $jsonResult;

Expected output:

{
"valid_format": true,
"valid_mx_records": false,
"possible_email_correction": "[email protected]",
"free_email_provider": false,
"disposable_email_provider": false,
"role_or_business_email": false,
"valid_host": false
}

Adding Custom Validations

To add a custom validation simply extend the EmailValidation\Validations\Validator class and implement the getResultResponse() and getValidatorName() methods. You then register the validation using the EmailValidation\EmailValidator->registerValidator() method.

Example code

// Validations/GmailValidator.php

<?php

namespace EmailValidation\Validations;

class GmailValidator extends Validator
{
    public function getValidatorName(): string
    {
        return 'is_gmail';
    }

    public function getResultResponse(): bool
    {
        $hostName = $this->getEmailAddress()->getHostPart();
        return strpos($hostName, 'gmail.com') !== false;
    }
}

// file-where-you-are-doing-your-validation.php

<?php

use EmailValidation\Validations\GmailValidator;

require __DIR__ . '/vendor/autoload.php';

$validator = EmailValidation\EmailValidatorFactory::create('[email protected]');

$validator->registerValidator(new GmailValidator());

echo $validator->getValidationResults()->asJson();

The expected output will be:

{
"is_gmail": true,
"valid_format": true,
"valid_mx_records": false,
"possible_email_correction": "",
"free_email_provider": true,
"disposable_email_provider": false,
"role_or_business_email": false,
"valid_host": false
}

Running in Docker

docker-compose up -d 

You can then validate an email by navigating to http://localhost:[email protected]. The result will be JSON string as per above.

Adding a custom data source

You can create your own data provider by creating a data provider class which implements the EmailValidation\EmailDataProviderInterface.

Example Code:

<?php

declare(strict_types=1);

namespace EmailValidation;

class CustomEmailDataProvider implements EmailDataProviderInterface
{
    public function getEmailProviders(): array
    {
        return ['custom.com'];
    }

    public function getTopLevelDomains(): array
    {
        return ['custom'];
    }

    public function getDisposableEmailProviders(): array
    {
        return ['custom.com', 'another.com'];
    }

    public function getRoleEmailPrefixes(): array
    {
        return ['custom'];
    }
}

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.

Can I manually update the disposable email provider data?

Yes, this project relies on this great repository for its list of disposable email providers. To fetch the latest list from that repo you can run

./scripts/update-dispsable-email-providers.php

from the command line. This will fetch the data and save it to ./src/data/disposable-email-providers.php

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].