TL;DR
- The Mail Exchange API is plain HTTPS and JSON at
https://mailexchange.com/api/v1. No SDK needed. POST /verifychecks one address and usually answers in a few seconds.POST /listschecks up to 100,000 addresses and you poll for the result.- Each result has a
state: deliverable, risky, undeliverable or unknown. The decision function below turns that into send, separate, skip, remove or retry. - Handle three statuses and you are done:
202(still checking),402(out of credits) and429(slow down). - Expect every branch: in 779,784 business addresses we checked, 18.1% were catch-all and 7.6% undeliverable.
Get an API key
Sign up, then create a key in your account under API keys. Every request sends the key as Authorization: Bearer your_key. Keep it in an environment variable, as the examples do, and out of source control. Plan prices are on the pricing page, and every plan includes the API.
What you need
PHP 8.0 or newer with the curl and json extensions, which are enabled on almost every host. The Guzzle variant is shown after the cURL example.
In Laravel or Symfony, use the framework HTTP client or Guzzle instead; the calls are the same (bearer header, JSON body).
Verify one address in PHP
Save this as verify.php; the list example reuses its helpers. mx_call sends the key, retries on 429 and throws on errors; verify_one handles the one tricky case, a slow mail server.
<?php
const MX_BASE = 'https://mailexchange.com/api/v1';
/** One API call. Retries 429 with exponential backoff, throws RuntimeException on other errors. */
function mx_call(string $method, string $path, ?array $body = null, int $retries = 4): array
{
for ($attempt = 0; ; $attempt++) {
$ch = curl_init(MX_BASE . $path);
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 45,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('MAILEXCHANGE_API_KEY'),
'Content-Type: application/json',
],
]);
if ($body !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
}
$raw = curl_exec($ch);
if ($raw === false) {
throw new RuntimeException('network error: ' . curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($status === 429 && $attempt < $retries) {
sleep(2 ** $attempt);
continue;
}
$data = json_decode($raw, true) ?? [];
if ($status >= 400) {
throw new RuntimeException("HTTP $status: " . ($data['error'] ?? $raw), $status);
}
return [$status, $data];
}
}
/** Turn a result into an action: send, separate, skip, remove or retry. */
function decide(array $result): string
{
return match ($result['state'] ?? '') {
'deliverable' => 'send',
// low_deliverability = catch-all domain. low_quality = role address, or disposable.
'risky' => ($result['reason'] ?? '') === 'low_deliverability' ? 'separate' : 'skip',
'undeliverable' => 'remove',
default => 'retry', // unknown, or still pending
};
}
function verify_one(string $email): array
{
[$status, $data] = mx_call('POST', '/verify', ['email' => $email]);
if ($status !== 202) {
return $data;
}
// 202: the mail server is slow. The check is running and already paid for.
// Do not post the address again, poll the list instead.
for ($i = 0; $i < 36; $i++) {
sleep(5);
[, $page] = mx_call('GET', "/lists/{$data['list_id']}/results?limit=1");
$row = $page['results'][0] ?? null;
if ($row && ($row['state'] ?? '') !== 'pending') {
return $row;
}
}
return $data; // still pending after 3 minutes: look again later with the same list_id
}
// Run directly: php verify.php [email protected] (skipped when another script requires this file)
if (realpath($argv[0] ?? '') === __FILE__) {
try {
$res = verify_one($argv[1] ?? '');
echo "{$res['email']} {$res['state']} " . ($res['reason'] ?? '') . ' -> ' . decide($res) . PHP_EOL;
} catch (RuntimeException $e) {
fwrite(STDERR, 'Mail Exchange error: ' . $e->getMessage() . PHP_EOL);
exit(1);
}
}
Run it:
MAILEXCHANGE_API_KEY=mx_live_xxx php verify.php [email protected]
Typical output looks like [email protected] deliverable accepted_email -> send.
/verify waits about 20 seconds and then returns 202 with {"state": "pending", "list_id": ...}. That check is already running and was already charged. Posting the same address again would start a second check and charge again, so read the result from /lists/{list_id}/results instead, as the code does. More in errors, credits and rate limits.The same call with Guzzle
If your project already depends on Guzzle (composer require guzzlehttp/guzzle), this is the equivalent of the single check. Set http_errors to false so you can read the error body yourself.
<?php
require 'vendor/autoload.php';
$client = new GuzzleHttp\Client([
'base_uri' => 'https://mailexchange.com/api/v1/',
'timeout' => 45,
'http_errors' => false,
'headers' => ['Authorization' => 'Bearer ' . getenv('MAILEXCHANGE_API_KEY')],
]);
$response = $client->post('verify', ['json' => ['email' => '[email protected]']]);
$status = $response->getStatusCode();
$data = json_decode((string) $response->getBody(), true);
if ($status >= 400) {
exit("HTTP $status: " . ($data['error'] ?? 'unknown error') . "\n");
}
if ($status === 202) {
// slow mail server: poll GET lists/{list_id}/results, do not post again
echo "pending, list {$data['list_id']}\n";
} else {
echo "{$data['email']} {$data['state']} {$data['reason']}\n";
}
Read the result and decide what to do
A result is a flat JSON object: email, state, reason, score, and the flags accept_all, role, free, disposable, plus mx. The state is what you branch on. The reason tells you why, and matters for the risky group. The decide function in the code above maps it like this:
| state | reason | decide() returns | Why |
|---|---|---|---|
| deliverable | accepted_email | send | The mail server accepted the mailbox. |
| risky | low_deliverability | separate | Catch-all domain. Cannot be confirmed either way. Send carefully or keep apart. |
| risky | low_quality, disposable | skip | Role address (info@, sales@) or a throwaway domain. |
| undeliverable | rejected_email, invalid_domain, invalid_email | remove | Will bounce. Drop it. |
| unknown | unavailable_smtp, no_connect, dns_error | retry | The server did not give a clear answer. The credit is refunded. |
The function is deliberately small so you can change it. A cold email team might send separate addresses only from established inboxes, as described in catch-all emails and cold email. A signup form might accept risky addresses but block undeliverable ones. The full list of states is in email verification statuses, and how it works explains the six checks behind them.
What result mix to expect
Plan your code for every branch, because all of them show up in real lists. In Mail Exchange's checks of 779,784 unique business addresses
across 200,799 domains (17 Oct to 22 Nov 2026), 18.1% came back risky with low_deliverability (catch-all),
7.8% risky with low_quality (role), 6.7% undeliverable with rejected_email and 0.9%
with invalid_domain. Unknown results were refunded. The sample is mostly B2B PR, media and marketing contact lists sent through our API, not a
random sample of all email, so a signup form will see a different mix. The point for your code: the separate and
retry branches are not edge cases.
Verify a list in PHP
For more than a handful of addresses, submit one list instead of looping over /verify. You get a list ID straight away, poll GET /lists/{id} until its status is done (or failed), then page through /lists/{id}/results 1,000 rows at a time. Duplicates inside the list are removed and not charged. Save this as verify-list.php with one address per line in emails.txt.
<?php
require __DIR__ . '/verify.php'; // mx_call() and decide() from the single-check example
function verify_list(array $emails): array
{
[, $created] = mx_call('POST', '/lists', ['emails' => $emails, 'name' => 'php-example']);
$id = $created['id'];
do {
[, $summary] = mx_call('GET', "/lists/$id");
echo "{$summary['checked']}/{$summary['total']} checked ({$summary['status']})\n";
$finished = in_array($summary['status'], ['done', 'failed'], true);
if (!$finished) {
sleep(5);
}
} while (!$finished);
if ($summary['status'] === 'failed') {
throw new RuntimeException("list $id failed");
}
$results = [];
for ($offset = 0; ; $offset += 1000) {
[, $page] = mx_call('GET', "/lists/$id/results?offset=$offset&limit=1000");
array_push($results, ...$page['results']);
if (count($page['results']) < 1000) {
break;
}
}
return [$summary, $results];
}
try {
$emails = array_values(array_filter(array_map('trim', file($argv[1]))));
[$summary, $results] = verify_list($emails);
echo 'counts: ' . json_encode($summary['counts']) . "\n";
$buckets = [];
foreach ($results as $row) {
$buckets[decide($row)][] = $row['email'];
}
foreach ($buckets as $action => $addresses) {
echo $action, ' ', count($addresses), "\n";
}
file_put_contents('send.txt', implode("\n", $buckets['send'] ?? []));
mx_call('DELETE', "/lists/{$summary['id']}"); // optional: remove the list and its results
} catch (RuntimeException $e) {
fwrite(STDERR, 'Mail Exchange error: ' . $e->getMessage() . PHP_EOL);
exit(1);
}
MAILEXCHANGE_API_KEY=mx_live_xxx php verify-list.php emails.txt
Instead of polling you can pass a callback_url and let us call you when the list is done, see webhooks and callbacks. The whole flow, including CSV download and deleting a list, is in verify a list with the API.
Errors, 402 and 429
Every error response is JSON with an error field, which the helper surfaces in the exception message. The ones to plan for:
- 429 means you hit the per-key rate limit. The helper waits 1, 2, 4 and 8 seconds and tries again, which is safe because a rate-limited request does no work and costs nothing.
- 402 means you do not have enough credits for the request. Retrying will not help. Stop, alert someone, and upgrade your plan or wait for it to renew.
GET /accountreturns your balance if you want to check first. - 401 means the key is missing or wrong. 400 means the request was malformed, for example no
email, or a list over 100,000 addresses.
Details and a status code table are in errors, credits and rate limits.
Common mistakes
- Looping over
/verifyfor a big file. A foreach over 50,000 addresses burns your rate limit and takes hours. Submit one list instead. - Posting again after a 202. The first check is still running and already charged. Poll its
list_id. - Treating
riskyasundeliverable. Catch-all addresses are often real people; keep them apart rather than deleting them (how). - Retrying a 402. Out of credits is not a transient error. Stop and upgrade your plan or wait for it to renew.
- Doing it all in a web request. Submit the list, store the ID, and finish in a queued job or a webhook.
- Trying to check mailboxes yourself. Syntax and MX checks are easy in PHP; the mailbox check needs outbound port 25, which AWS EC2 blocks to public addresses by default and Google Compute Engine blocks to destinations outside your network (both checked 2026-11-22).
If you'd rather test before writing code, upload a CSV in the app first: the free trial gives you 25 checks, and plans start at $49 a month for 10,000 verifications and daily checks on 10 sending domains.
Frequently asked questions
Is there an official PHP SDK for the Mail Exchange API?
No, and none is needed. The API is plain HTTPS and JSON, so the examples on this page use only cURL (or Guzzle).
How do I get an API key?
Sign up, then create a key in your account under API keys. Send the key as a bearer token in the Authorization header.
What should I do when /verify returns 202?
Do not send the address again. The check is already running and paid for. Read the result from /lists/{list_id}/results using the list_id in the 202 response, until the state is no longer pending.
Can I verify an email address in PHP without an API?
Partly. filter_var with FILTER_VALIDATE_EMAIL checks syntax and checkdnsrr or getmxrr checks that the domain has mail servers. Confirming that the mailbox exists needs an SMTP conversation on port 25 from an IP with a good reputation, which most cloud hosts block by default, so that step is where an API helps.
How much does each check cost?
One credit per unique address, charged when you submit. Duplicates are not charged and unknown results are refunded when the list finishes. Plans start at $49 a month for 10,000 verifications and daily checks on 10 sending domains, and every plan includes the API.
Related
- Email verification API reference
- Email verification statuses
- Verify a list with the API
- Webhooks and callbacks
- Errors, credits and rate limits
- Pricing and all developer guides
- Email verification API for Python
- Email verification API for Node.js
- Email verification API for Ruby
- Email verification API for Go
- Email verification API for Java
- Email verification API for C#
