PHP client

Plain cURL, PHP 8+, no packages:

<?php
// InboxDome.php
class InboxDome
{
    private const BASE = 'https://inboxdome.com';

    public function __construct(private string $apiKey) {}

    private function req(string $method, string $path, ?array $body = null): ?array
    {
        $ch = curl_init(self::BASE . $path);
        curl_setopt_array($ch, [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_CUSTOMREQUEST => $method,
            CURLOPT_TIMEOUT => 55,
            CURLOPT_HTTPHEADER => [
                'Authorization: Bearer ' . $this->apiKey,
                'Content-Type: application/json',
            ],
        ]);
        if ($body !== null) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
        }
        $res = curl_exec($ch);
        $code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
        curl_close($ch);
        if ($code >= 400) {
            throw new RuntimeException("InboxDome $path → HTTP $code: $res");
        }
        return $res === '' ? null : json_decode($res, true);
    }

    public function createInbox(array $opts = []): array
    {
        return $this->req('POST', '/v1/inboxes', $opts ?: new stdClass())['inbox'];
    }

    public function waitForOtp(string $inboxId, int $timeout = 30): string
    {
        $r = $this->req('GET', "/v1/inboxes/$inboxId/wait?for=otp&timeoutSeconds=$timeout");
        return $r['otp']['value'];
    }

    public function waitForMessage(string $inboxId, int $timeout = 30): array
    {
        return $this->req('GET', "/v1/inboxes/$inboxId/wait?timeoutSeconds=$timeout")['message'];
    }

    public function listMessages(string $inboxId): array
    {
        return $this->req('GET', "/v1/inboxes/$inboxId/messages")['data'];
    }
}

WooCommerce example (PHPUnit)

public function test_order_confirmation_email(): void
{
    $dome = new InboxDome(getenv('INBOXDOME_KEY'));
    $inbox = $dome->createInbox();

    // Place a WooCommerce order with the disposable address
    $order = wc_create_order();
    $order->set_billing_email($inbox['emailAddress']);
    $order->set_status('processing'); // triggers the confirmation email
    $order->save();

    $message = $dome->waitForMessage($inbox['id'], 45);
    $this->assertStringContainsString('order', strtolower($message['subject']));
}

API reference →