Skip to content

Laravel

duta/duta-php includes a Laravel mail driver. Your existing Mailables, notifications and Mail:: calls send through Duta without a code change. It supports the Laravel releases that still receive security fixes, 12 and 13.

  1. Install the package. Laravel finds it on its own.

    Terminal window
    composer require duta/duta-php
  2. Set your key and choose the mailer in .env:

    DUTA_API_KEY=duta_xxxxxxxxxxxxxxxx
    MAIL_MAILER=duta
    MAIL_FROM_ADDRESS=resit@kedai.my
    MAIL_FROM_NAME="Kedai Runcit"

    The from address must be on a verified domain, or your sandbox address on the Free plan.

  3. Send as you already do.

    Mail::to($order->customer)->send(new OrderReceipt($order));

Everything a Mailable sets is carried over: from, to, cc, bcc, reply-to, the subject, the HTML and text bodies, attachments and custom headers. Names are kept exactly as written, even with quotes or commas in them.

Two headers on a Mailable are read by the driver rather than sent:

use Illuminate\Mail\Mailables\Headers;
public function headers(): Headers
{
return new Headers(text: [
'X-Duta-Tag-type' => 'receipt',
'X-Duta-Idempotency-Key' => "receipt-{$this->order->id}",
]);
}
  • X-Duta-Tag-<name> becomes a tag: here type=receipt.
  • X-Duta-Idempotency-Key makes the send safe to repeat for 24 hours. Use it on queued mail: if the job runs twice, the customer gets one email. See Idempotency.

Inject Duta\Duta for everything beyond mail, such as usage or suppressions:

public function __construct(private \Duta\Duta $duta) {}
public function usage(): array
{
return $this->duta->usage->get();
}

The key comes from services.duta.key when set, otherwise DUTA_API_KEY. To keep it in config/services.php:

'duta' => [
'key' => env('DUTA_API_KEY'),
],