PHP SDK

The official camelmailer/camelmailer package is a clean object client for PHP 8.1+, built on a swappable PSR-18 HTTP client so you can stub it in tests.

Install

terminal
composer require camelmailer/camelmailer

Using Laravel? Reach for the Laravel packageinstead. It wires this SDK into Laravel's mail system.

Quickstart

mailer.php
<?php
$camelmailer = CamelMailer\CamelMailer::client('cm_xxxxxxxx');

$result = $camelmailer->emails->send([
    'from' => 'billing@acme.com',
    'to' => ['ada@example.com'],
    'subject' => 'Your receipt',
    'html_body' => '<p>Thanks for your purchase.</p>',
]);

echo $result->message_id;

Send with a template

template.php
$camelmailer->emails->sendWithTemplate([
    'from' => 'hello@acme.com',
    'to' => ['ada@example.com'],
    'template' => 'welcome',
    'template_model' => ['name' => 'Ada'],
]);

Error handling

Stable API error codes surface as typed exceptions; TransporterException covers network-level failures.

errors.php
use CamelMailer\Exceptions\ErrorException;
use CamelMailer\Exceptions\TransporterException;

try {
    $camelmailer->emails->send([/* … */]);
} catch (ErrorException $e) {
    $e->code;            // 'ValidationError', 'Unauthorized', 'NotFound', ...
    $e->getMessage();    // human-readable message
    $e->getStatusCode(); // HTTP status
} catch (TransporterException $e) {
    // network-level failure
}

Self-hosted instances

The client defaults to the cloud (https://app.camelmailer.com). Point it at your own instance with the baseUrl argument:

self-hosted.php
$camelmailer = CamelMailer\CamelMailer::client(
    'cm_xxxxxxxx',
    baseUrl: 'https://mail.example.com',
);
Full field reference: Messages API.

GitHub repository · Packagist package