The simplest possible way to verify an email in PHP.
To use this library, you'll need to create a free Email Verification account: https://emailverification.whoisxmlapi.com/
If you haven't done this yet, please do so now.
To install email-verifier
using composer, simply run:
$ composer require whois-api/email-verifier
In the root of your project directory.
To use the library, use Composer's autoload
require_once __DIR__ . "/vendor/autoload.php";
- PHP 5.6.x
- PHP 7.0.x
- PHP 7.1.x
- PHP 7.2.x
- mbstring
- mbregex
- json
- curl
Full API documentation available here
Once you have email-verifier
installed, you can use it to easily verify an
email address. Email verification performs a number of checks to ensure a
given email address is actually valid.
This library gives you access to all sorts of email verification data that you can use in your application in any number of ways.
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use WhoisApi\EmailVerifier\Builders\ClientBuilder;
$builder = new ClientBuilder();
$client = $builder->build('Your API key');
try {
echo $client->getRawData('[email protected]', 'json') . PHP_EOL;
/* Disable refreshing */
echo print_r($client->get('[email protected]', ['_hardRefresh']), true) . PHP_EOL;
$result = $client->get('[email protected]', ['_hardRefresh']);
echo 'Email: ' . $result->emailAddress . PHP_EOL;
echo 'Format: ' . ($result->formatCheck ? 'valid' : 'invalid') . PHP_EOL;
echo 'DNS: '. ($result->dnsCheck ? 'resolved' : 'not resolved') . PHP_EOL;
echo 'SMTP: ' . ($result->smtpCheck ? 'working' : 'not working') . PHP_EOL;
echo 'Free: ' . ($result->freeCheck ? 'yes' : 'no') . PHP_EOL;
echo 'Catch all: ' . ($result->catchAllCheck ? 'yes' : 'no') . PHP_EOL;
echo 'Disposable: ' . ($result->disposableCheck ? 'yes' : 'no') . PHP_EOL;
} catch (\Throwable $exception) {
echo "Error: {$exception->getCode()} {$exception->getMessage()}" . PHP_EOL;
}
More examples you can see in the "examples" directory.
Before run these examples you need to specify your API key as an environment variable:
export API_KEY="<Your-API-key>"
php examples/basic.php
Here's the sort of data you might get back when performing a email verification request:
{
"emailAddress": "[email protected]",
"formatCheck": "true",
"smtpCheck": "true",
"dnsCheck": "true",
"freeCheck": "false",
"disposableCheck": "false",
"catchAllCheck": "true",
"mxRecords": [
"ALT1.ASPMX.L.GOOGLE.com",
"ALT2.ASPMX.L.GOOGLE.com",
"ASPMX.L.GOOGLE.com",
"ASPMX2.GOOGLEMAIL.com",
"ASPMX3.GOOGLEMAIL.com",
"mx.yandex.net"
],
"audit": {
"auditCreatedDate": "2018-04-19 18:12:45.000 UTC",
"auditUpdatedDate": "2018-04-19 18:12:45.000 UTC"
}
}
After you clone this repository you need to install all requirements:
$ composer install
To run tests you can use the following command
$ composer run-script test