LettermintLettermint
  • Knowledge base
  • Community
  • Changelog
  • Support
  • Documentation
  • Sending API
  • Team API
  • MCP server
Get started
Send email
    Send with
      SDKs
        Node.jsPHPPythonGoJava.NETElixir
      Frameworks
    SMTP
    Email activitySchedulingTest emailsTLSIdempotencySuppressionsTagsInline imagesData retentionSending limits
    Tracking
Receive email
Manage
Resources
SDKs

PHP

Use the official Lettermint PHP SDK to send email from a PHP application. If you use Laravel, use the Laravel mail driver. If you use Symfony Mailer, use the Symfony guide. See SDKs and integrations for other packages.

Requirements

Before you start you need:

  • PHP 8.2 or newer with Composer
  • A Lettermint account with a verified sending domain
  • A Project API token from your project settings

If your domain is not verified yet, follow the domain setup guide first so your mail reaches the inbox instead of the spam folder.

Building a Laravel app? Use the Laravel guide instead. It wraps this SDK in a mail driver that works with Laravel's Mail facade, Mailables, and queues.

1. Installation

Install the SDK via Composer:

TerminalCode
composer require lettermint/lettermint-php

2. Send your first email

Initialize the email client with your Project API token:

Code
<?php require_once 'vendor/autoload.php'; $email = Lettermint\Lettermint::email(getenv('LETTERMINT_PROJECT_TOKEN'));

Send your first email:

Code
$response = $email ->from('John Doe <john@yourdomain.com>') ->to('recipient@example.com') ->subject('Hello from Lettermint!') ->text('Hello! This is a test email.') ->send(); echo "Email sent with ID: " . $response->message_id;

3. Email features

Basic email

Send a simple text or HTML email:

Code
$email ->from('John Doe <john@yourdomain.com>') ->to('recipient@example.com') ->subject('Your account is ready!') ->html('<h1>Welcome!</h1><p>Thanks for signing up.</p>') ->text('Welcome! Thanks for signing up.') ->send();

Multiple recipients

Send to multiple recipients using CC and BCC:

Code
$email ->from('John Doe <john@yourdomain.com>') ->to('user1@example.com', 'user2@example.com') ->cc('manager@yourdomain.com') ->bcc('archive@yourdomain.com') ->subject('Monthly Newsletter') ->html('<h1>This Month\'s Updates</h1>') ->send();

Custom headers and reply-to

Add custom headers and set reply-to addresses:

Code
$email ->from('support@yourdomain.com') ->to('customer@example.com') ->replyTo('help@yourdomain.com') ->subject('Support Ticket #12345') ->headers([ 'X-Priority' => '1', 'X-Ticket-ID' => '12345' ]) ->html('<p>Your support ticket has been updated.</p>') ->send();

Metadata

Add metadata for tracking and webhook payloads:

Code
$email ->from('notifications@yourdomain.com') ->to('user@example.com') ->subject('Order Confirmation') ->metadata([ 'order_id' => '12345', 'customer_id' => 'cust_789', 'campaign' => 'order_confirmation' ]) ->html('<p>Your order has been confirmed.</p>') ->send();

Metadata is included in webhook payloads but not added to the actual email headers. Use it for tracking and analytics purposes.

Tags

Categorize emails for filtering and analytics:

Code
$email ->from('alerts@yourdomain.com') ->to('admin@example.com') ->subject('System Alert') ->tag('system-alerts') ->html('<p>Critical system alert detected.</p>') ->send();

This SDK example uses the existing singular tag. It has no deprecation date. Use the raw HTTP API to send structured tags until this SDK has a multi-tag method. See Tags documentation.

Route selection

Direct emails to specific routes within your project:

Code
$email ->from('notifications@yourdomain.com') ->to('user@example.com') ->subject('Welcome!') ->route('transactional') ->html('<p>Welcome to our platform.</p>') ->send();

Idempotency

Pass an idempotency key so a retry never sends the same email twice. If a request with the same key is repeated within the idempotency window, Lettermint returns the original result instead of sending again:

Code
$email ->from('notifications@yourdomain.com') ->to('user@example.com') ->subject('Order Confirmation') ->idempotencyKey('order-confirmation-12345') ->html('<p>Your order has been confirmed.</p>') ->send();

Derive the key from something stable in your domain, such as an order or invoice ID, so the same business event always maps to the same key. See the idempotency documentation for the full behaviour.

File attachments

Attach files to your emails:

Code
// Read file content $fileContent = file_get_contents('/path/to/document.pdf'); $email ->from('invoices@yourdomain.com') ->to('customer@example.com') ->subject('Your Invoice') ->html('<p>Please find your invoice attached.</p>') ->attach('invoice.pdf', base64_encode($fileContent)) ->send();

4. Send an order confirmation

A real transactional send usually pulls several of these features together. This example sends a receipt with an HTML and plain-text body, tags it for analytics, attaches the order and customer IDs as metadata, and uses an idempotency key so a retry never emails the customer twice:

Code
<?php require_once 'vendor/autoload.php'; $email = Lettermint\Lettermint::email(getenv('LETTERMINT_PROJECT_TOKEN')); // $order comes from your application (database, cart, etc.) $order = [ 'id' => 'ORD-12345', 'number' => '12345', 'total' => '€49.00', 'customer_email' => 'customer@example.com', 'customer_id' => 'cust_789', ]; $response = $email ->from('Acme Store <orders@yourdomain.com>') ->to($order['customer_email']) ->replyTo('support@yourdomain.com') ->subject("Order {$order['number']} confirmed") ->html("<h1>Thanks for your order</h1><p>Order {$order['number']} totalling {$order['total']} is confirmed.</p>") ->text("Thanks for your order. Order {$order['number']} totalling {$order['total']} is confirmed.") ->tag('order-confirmation') ->metadata([ 'order_id' => $order['id'], 'customer_id' => $order['customer_id'], ]) ->idempotencyKey("order-confirmation-{$order['id']}") ->route('transactional') ->send(); echo "Order confirmation sent: " . $response->message_id;

The metadata you attach here travels with every webhook event for the message, so a later delivery or bounce maps straight back to the order in your database.

5. Response

Code
$response = $email ->from('John Doe <john@yourdomain.com>') ->to('recipient@example.com') ->subject('Test') ->text('Hello!') ->send(); echo $response->message_id; // Email ID echo $response->status; // Current status

Track delivery, opens, and bounces

Sending is only half of a transactional setup. To see what happens after a message leaves your app, combine the SDK with Lettermint's platform features:

  • Email tracking records opens and clicks, with bot filtering so your metrics stay accurate.
  • Webhooks push delivery, bounce, and complaint events to your server in real time, so you can update order records or suppress bad addresses.
  • Test addresses let you trigger a hard or soft bounce on demand while you build and verify your webhook handler.

Tracking is configured per route, so turn it on for the route your app sends through, then read the results from your dashboard or your webhook endpoint.

FAQ

Does the SDK work with Laravel or another framework?

The SDK works in any PHP project, including Symfony and plain PHP. If you use Laravel, install the dedicated Laravel mail driver instead, which integrates with the Mail facade, Mailables, and queues rather than calling the SDK directly.

Which PHP versions are supported?

PHP 8.2 or newer. Install the SDK with a single composer require lettermint/lettermint-php.

How do I stop the same email being sent twice?

Add an idempotency key with ->idempotencyKey(), derived from a stable ID such as an order number. A repeated request with the same key returns the original result instead of sending again. See the idempotency documentation.

Is Lettermint email GDPR compliant and EU-hosted?

Yes. Lettermint runs exclusively on European infrastructure and processes email in line with GDPR, so transactional mail from your PHP app is handled inside the EU.

How do I track opens, clicks, and bounces?

Enable tracking on your route and subscribe to webhooks to receive delivery, open, and bounce events. Use the test addresses to simulate bounces while you build your handler.

Next steps

Tags

Organize and filter emails with tags.

Tracking

Track opens, clicks, and deliverability.

Webhooks

Receive delivery events through webhooks.

Laravel Driver

Use the dedicated Lettermint mail driver for Laravel.

GitHub Repository

Find the complete source code, report issues, or contribute on GitHub.

Node.jsPython
On this page
  • Requirements
  • 1. Installation
  • 2. Send your first email
  • 3. Email features
    • Basic email
    • Multiple recipients
    • Custom headers and reply-to
    • Metadata
    • Tags
    • Route selection
    • Idempotency
    • File attachments
  • 4. Send an order confirmation
  • 5. Response
  • Track delivery, opens, and bounces
  • FAQ
  • Next steps
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP