Last updated: August 28, 2026.
An HTTP email API can return structured errors, message IDs, templates, and delivery webhooks. The endpoint and payload vary, but the transport pattern is consistent.
Call an email API with cURL
<?php
$payload = ['to' => [['email' => '[email protected]']], 'subject' => 'Receipt', 'text' => 'Ready'];
$ch = curl_init('https://api.mail-provider.example/v1/messages');
curl_setopt_array($ch, [
CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 15,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('MAIL_API_TOKEN'), 'Content-Type: application/json', 'Idempotency-Key: order-1042-receipt'],
CURLOPT_POSTFIELDS => json_encode($payload, JSON_THROW_ON_ERROR),
]);
$response = curl_exec($ch); $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($response === false || $status < 200 || $status >= 300) throw new RuntimeException('Mail API failed.');
curl_close($ch);Track delivery
- Use the provider’s documented payload.
- Store the returned message ID.
- Retry only temporary failures.
- Validate webhook signatures before updating status.
Reference: PHP cURL reference.