Blog
Guides
#php#email#sdk

Sending Transactional Email with PHP

A step-by-step guide to sending reliable transactional email from PHP using the Digitel Africa Mail SDK — from install to attachments and error handling.

ANAnonymous21 Aug 2026 · 7 min read

Transactional email — order confirmations, password resets, invoices — has to arrive, and it has to arrive fast. This guide shows how to send it from PHP with the Digitel Africa Mail SDK, on a domain that lands in the inbox.

From composer install to a delivered message in about five minutes.

Install the SDK

The SDK supports PHP 8.1+ and installs with Composer. It wraps authentication, retries and typed responses so you are not hand-building HTTP requests.

bash
composer require digitel/sdk

Authenticate

Create a client with your API key. Never hard-code the key — read it from the environment so it stays out of version control.

php
<?php
use Digitel\Client;

$digitel = new Client(getenv('DIGITEL_API_KEY'));

Send your first email

Create a message from a verified sending domain. The call returns immediately with a message id you can use to track delivery.

php
$message = $digitel->email->messages->send([
    'from'    => '[email protected]',
    'to'      => ['[email protected]'],
    'subject' => 'Your order is confirmed',
    'html'    => '<h1>Thanks for your order</h1>',
]);

echo $message->id;

Read the response

A successful call returns the queued message. Store the id if you want to reconcile delivery events later.

json
{
  "id": "msg_01HZY8QK3P4RN2",
  "object": "email.message",
  "status": "queued",
  "to": ["[email protected]"],
  "created_at": "2026-08-21T09:15:42Z"
}

Attach files and send HTML

Pass a base64-encoded attachment alongside your HTML body — handy for invoices and receipts.

php
$message = $digitel->email->messages->send([
    'from'        => '[email protected]',
    'to'          => ['[email protected]'],
    'subject'     => 'Your invoice',
    'html'        => $renderedHtml,
    'attachments' => [
        ['filename' => 'invoice.pdf', 'content' => base64_encode($pdf)],
    ],
]);

Handle errors

Wrap sends in a try/catch and log the request_id — support can trace any message from it.

php
use Digitel\Exception\ApiException;

try {
    $digitel->email->messages->send($payload);
} catch (ApiException $e) {
    error_log("Send failed: {$e->getMessage()} ({$e->requestId})");
}

Authenticate from the environment, send from a verified domain, and log the request id. Do those three things and email stops being a mystery.

That is the whole flow. See the full reference in the docs, and set up SPF, DKIM and DMARC on your domain so every message earns its reputation.

#php#email#sdk