Airmail / Developer guides

PHP Email API with Airmail

A standard PHP cURL request is enough. No provider-specific Composer SDK is required.

Free Developer beta. Verified domain and manual sending approval required.

PHP cURL example

Use PHP with the cURL extension and JSON support. Set AIRMAIL_API_KEY in the server environment. Replace the sender and recipient examples, include this code in a server-side script, and run it only after activation. The example bounds connect and request time, closes the cURL handle and prints the accepted message ID. Persist that ID in your application. Never expose the key to a browser.

$payload = json_encode([
  'from' => [
    'email' => 'notifications@example.com',
    'name' => 'Example'
  ],
  'to' => [
    [
      'email' => 'recipient@example.net'
    ]
  ],
  'subject' => 'Welcome',
  'text' => 'Your account is ready.'
], JSON_THROW_ON_ERROR);
$request = curl_init('https://api.airmailai.tech/v1/messages');
curl_setopt_array($request, [
  CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => $payload,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CONNECTTIMEOUT => 10,
  CURLOPT_TIMEOUT => 20,
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer ' . getenv('AIRMAIL_API_KEY'),
    'Content-Type: application/json',
    'Idempotency-Key: account-481-welcome'
  ]
]);
$body = curl_exec($request);
$status = curl_getinfo($request, CURLINFO_HTTP_CODE);
curl_close($request);
if ($body === false || $status >= 400) throw new RuntimeException('Airmail request failed');
$result = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
echo $result['id'] . PHP_EOL;

Handle retries without duplicates

Persist one Idempotency-Key per logical REST send. Reuse the same key and identical payload when a request times out; do not create a new key for a retry. A 202 response means durable acceptance, not final delivery. Save the msg_* ID and inspect Messages or signed webhooks for the result. After acceptance, do not resubmit deferred mail: Airmail and its delivery service own those retries. Do not automatically fail over an ambiguous send to another provider, because the first provider may already have accepted it.

Before your first production message

Start with the free Developer beta. Verify your account, create a workspace and add a domain you control: example.com and mail.example.com are both supported. Publish the records shown in Domains. Merge an existing SPF policy rather than adding another; preserve a valid existing DMARC policy. Create an API key after verification, use the dashboard for one owner-controlled validation, and request production approval. SMTP credentials become available after activation. No repository or SSH access is needed.

Know the boundaries

Airmail is a controlled public beta. Production sending requires manual approval. Paid plans remain request-access for general signups; payment never grants sending approval. Monthly allowance, daily safety quota and provider pacing are different limits. Sending is transactional by default; partnership/campaign access needs separate approval and is not a purchased-list service. Dedicated reputation isolation is not currently included. There is no inbox-placement guarantee or published OTP delivery SLA.

Start with one verified domain

All integration guides / Ask about your use case