<?php
$key = getenv('WAZOBIA_API_KEY');
if (!$key) throw new RuntimeException('Set WAZOBIA_API_KEY');
$curl = curl_init('https://app.wazobiamail.com/api/v1/sending/domains');
curl_setopt_array($curl, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'X-API-Key: ' . $key],
CURLOPT_POSTFIELDS => json_encode(['domain' => 'mail.example.com'], JSON_THROW_ON_ERROR),
]);
$body = curl_exec($curl);
if ($body === false) throw new RuntimeException(curl_error($curl));
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$result = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
if ($status >= 300 || ($result['success'] ?? false) !== true) {
throw new RuntimeException($result['message'] ?? 'Domain creation failed');
}
print_r($result);