Skip to content

Search documentation

Search pages and sections

Integrations

PHP SDK

The official PHP SDK for PHP 8.1+: send emails, manage templates and suppressions, and verify webhooks — with any framework.

Install

composer require hulakimail/hulakimail-php

Requires PHP 8.1+. Uses any installed PSR-18 HTTP client (Guzzle, Symfony HttpClient…) or falls back to cURL. Using Laravel? See the Laravel package.

Send an email

<?php
use HulakiMail\HulakiMail;

$hulakimail = new HulakiMail(getenv('HULAKIMAIL_API_KEY'));

$email = $hulakimail->emails->send([
    'from' => 'Acme <[email protected]>',
    'to' => ['[email protected]'],
    'template_id' => 'tpl_01JD3R2K6Q8W4M1T7Z9X5B3N0C',
    'variables' => ['first_name' => 'Ada'],
    'attachments' => [
        ['filename' => 'invoice.pdf', 'content' => base64_encode(file_get_contents('invoice.pdf'))],
    ],
], ['idempotency_key' => 'receipt-' . $order->id]);

echo $email['id'];

Other resources

$hulakimail->emails->batch([$email1, $email2]);   // up to 100
$hulakimail->emails->get('msg_01JD…');
$hulakimail->emails->cancel('msg_01JD…');

foreach ($hulakimail->emails->listAll(['status' => 'bounced']) as $email) {
    // …
}

$hulakimail->templates->create(['name' => 'Welcome', 'subject' => 'Hi {{first_name}}', 'html' => '…']);
$hulakimail->suppressions->create('[email protected]');
$hulakimail->domains->get('acme.com');

Errors

use HulakiMail\Exception\HulakiMailException;
use HulakiMail\Exception\RateLimitException;

try {
    $hulakimail->emails->send($params);
} catch (RateLimitException $e) {
    sleep($e->getRetryAfter() ?? 1);
} catch (HulakiMailException $e) {
    error_log($e->getMessage() . ' (request ' . $e->getRequestId() . ')');
}

Webhooks

use HulakiMail\Webhook;

$payload = file_get_contents('php://input');
$header = $_SERVER['HTTP_HULAKIMAIL_SIGNATURE'] ?? null;

try {
    $event = Webhook::verify($payload, $header, getenv('HULAKIMAIL_WEBHOOK_SECRET'));
} catch (\Throwable $e) {
    http_response_code(400);
    exit;
}

// $event['type'], $event['data'] …
http_response_code(200);

Something unclear or missing? Tell us.