# Validate email addresses with PHP

The ValidatedMails API returns structural and operational deliverability signals (syntax, DNS routing, and SMTP behavior). It validates routing-layer deliverability using DNS and SMTP signals and returns deterministic outcomes for signups, lead forms, CRMs, and data pipelines.

Response model:

SMTP acceptance reflects recipient routing acceptance at validation time. Final inbox placement is governed by sender reputation and provider filtering policies.

## Quickstart

You can call `/validate` in two ways: a simple `GET` request with query parameters, or a `POST` request with a JSON body. Use whichever fits your stack.

```php
GET https://api.validatedmails.com/validate/?email=ada@acme.com&token=YOUR_API_TOKEN
```

```php
POST https://api.validatedmails.com/validate?token=YOUR_API_TOKEN
Content-Type: application/json

{
  "email": "ada@acme.com"
}
```

The response includes a four-state verdict (`status`), a boolean convenience field (`is_valid`), a confidence score, and the `trace_id` you should log for support and debugging.

## PHP example (curl + file_get_contents)

Use `curl` for GET requests or `file_get_contents` with a JSON body for POST requests. The example below keeps the response parsing explicit and captures the fields you will use in product logic.

```php
<?php

$apiBaseUrl = getenv('VALIDATEDMAILS_API_BASE_URL') ?: 'https://api.validatedmails.com';
$apiToken = getenv('VALIDATEDMAILS_API_TOKEN') ?: 'YOUR_API_TOKEN';

function validateEmailGet(string $email, string $apiBaseUrl, string $apiToken): array {
    $query = http_build_query([
        'email' => $email,
        'token' => $apiToken,
    ]);
    $url = rtrim($apiBaseUrl, '/') . "/validate/?{$query}";

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 8);
    $response = curl_exec($ch);
    curl_close($ch);

    return json_decode($response ?: '{}', true);
}

function validateEmailPost(string $email, string $apiBaseUrl, string $apiToken): array {
    $url = rtrim($apiBaseUrl, '/') . "/validate?token={$apiToken}";
    $payload = json_encode(['email' => $email]);

    $context = stream_context_create([
        'http' => [
            'method' => 'POST',
            'header' => "Content-Type: application/json
",
            'content' => $payload,
            'timeout' => 8,
        ],
    ]);

    $response = file_get_contents($url, false, $context);

    return json_decode($response ?: '{}', true);
}

$result = validateEmailGet('ada@acme.com', $apiBaseUrl, $apiToken);
$status = $result['status'] ?? 'unknown';
$isValid = $result['is_valid'] ?? false;
$score = $result['score'] ?? 0;
$traceId = $result['trace_id'] ?? '';

echo "status: {$status}
";
echo "is_valid: " . ($isValid ? 'true' : 'false') . "
";
echo "score: {$score}
";
echo "trace_id: {$traceId}
";

if ($status === 'valid') {
    echo "Accept signup
";
} elseif ($status === 'invalid') {
    echo "Reject signup
";
} else {
    echo "Risky or unknown: apply your review or confirmation policy
";
}
?>
```

Sample response payload:

```json
{
  "is_valid": true,
  "status": "valid",
  "score": 95,
  "smtp_ok": true,
  "accept_all": false,
  "disposable": false,
  "role": false,
  "free": false,
  "tag": false,
  "mx_ok": true,
  "a_ok": true,
  "trace_id": "..."
}
```

## Interpreting the response

### status + is_valid

- valid: syntax and routing are valid, and SMTP accepted the recipient.
- invalid: syntax is invalid or SMTP explicitly rejected the recipient.
- risky: review catch-all and other risk signals under your acceptance policy.
- unknown: routing cannot be conclusively established within configured DNS or SMTP time budgets.

`is_valid` mirrors `status === "valid"`. Use `status` when you need the full four-state outcome.

### score + trace_id

`score` is a 0-100 confidence indicator that blends SMTP, DNS, and risk flags. Treat it as a ranking input in your policy.

Log `trace_id` with request metadata for support, audit trails, and debugging.

## High-volume workloads

Use `/validate` for real-time single-address checks and`POST /validate/batch` for lists, imports, and background workers. The synchronous batch endpoint returns ordered per-address results. Use Bulk validation jobs for very large CSV imports and full-list processing.

- Send up to 100 emails per synchronous batch request.
- Run parallel batch workers to reach your target throughput.
- Use Bulk validation jobs for files up to 200,000 rows, subject to upload-size limits.
- Retry HTTP `429`, HTTP `5xx`, network errors, and client timeouts with bounded backoff. Honor `Retry-After` when present.

## Handling outcomes

### valid

Accept the address and continue the workflow.

### invalid

Reject or quarantine the address to prevent hard bounces.

### unknown

Treat as deferred verification: confirmation email, OTP, or manual review.
