EmailCheckerEmailChecker

Documentação · PHP

Validar email em PHP

PHP tem 2 caminhos: cURL nativo (zero dependência, mais verboso) ou Guzzle (padrão moderno, requer composer). Os exemplos abaixo usam Guzzle pela legibilidade — versão cURL no final das notas.

Instalação (composer)

bash
composer require guzzlehttp/guzzle

Single · POST /validate/single

Validar 1 email

Endpoint síncrono. Retorna em 1–3 segundos com result, score, reason e atributos. Custa 1 crédito por chamada bem-sucedida.

php
<?php
// validate_single.php
require 'vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;

$apiKey = getenv('EMAILCHECKER_API_KEY');
$baseUrl = 'https://app.emailchecker.email/api/v1';

$client = new Client([
    'base_uri' => $baseUrl,
    'timeout' => 15.0,
    'headers' => [
        'Authorization' => "Bearer {$apiKey}",
        'Content-Type' => 'application/json',
    ],
]);

function validateEmail(Client $client, string $email): array {
    try {
        $response = $client->post('/validate/single', [
            'json' => ['email' => $email],
        ]);
        return json_decode((string) $response->getBody(), true);
    } catch (RequestException $e) {
        throw new \RuntimeException("EmailChecker API error: " . $e->getMessage());
    }
}

// uso
$result = validateEmail($client, 'joao@empresa.com.br');
echo $result['result'];  // "deliverable" | ...
echo $result['score'];   // 0-100

Batch · POST /validate/batch

Validar em lote

Endpoint async. Submete array de emails, retorna job_id. Use webhook (recomendado) ou polling pra pegar resultado. Suporta até 100k emails por job.

php
<?php
// validate_batch.php
function submitBatch(Client $client, array $emails, ?string $webhookUrl = null): string {
    $payload = ['emails' => $emails];
    if ($webhookUrl) {
        $payload['webhook_url'] = $webhookUrl;
    }
    $response = $client->post('/validate/batch', ['json' => $payload]);
    $data = json_decode((string) $response->getBody(), true);
    return $data['job_id'];
}

function getBatchResult(Client $client, string $jobId): array {
    $response = $client->get("/validate/batch/{$jobId}");
    return json_decode((string) $response->getBody(), true);
}

// uso
$jobId = submitBatch($client, ['a@x.com', 'b@y.com'], 'https://seu-app.com/webhook/ec');

Webhook handler

Receber notificação do job

Quando o batch termina, a gente faz POST pra URL que você passou em webhook_url. Retry automático em até 3 tentativas (1s, 5s, 30s) se você responder com erro 5xx.

php
<?php
// webhook.php (PHP nativo, sem framework)
$input = json_decode(file_get_contents('php://input'), true);

if ($input['status'] !== 'completed') {
    http_response_code(200);
    echo json_encode(['ok' => true]);
    exit;
}

foreach ($input['results'] as $r) {
    if ($r['result'] === 'deliverable') {
        // salva no banco, dispara worker, etc.
    }
}

http_response_code(200);
echo json_encode(['ok' => true]);

Boas práticas

Mais linguagens

Exemplos em outras linguagens

Comece agora

Pronto pra parar de mandar email pra endereço morto?

Comece grátis com 500 créditos. Sem cartão, sem compromisso.