LettermintLettermint
  • Knowledge base
  • Community
  • Changelog
  • Support
  • Documentation
  • Sending API
  • Team API
Getting started
Guides
    Node.jsPHPPythonGoLaravelMagento 2NuxtJava
    SMTP
Platform
Resources
Guides

PHP

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 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();

One tag per message. Tags can contain letters, numbers, hyphens, underscores, and spaces (max 255 characters). See Tags documentation for more details.

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();

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. 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

Next Steps

Tags

Organize and filter emails with tags.

Tracking

Track opens, clicks, and deliverability.

Webhooks

Receive real-time delivery notifications.

SMTP Alternative

Send via SMTP instead of the API.

GitHub Repository

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

Last modified on May 11, 2026
Node.jsPython
On this page
  • 1. Installation
  • 2. Send your first email
  • 3. Email Features
    • Basic Email
    • Multiple Recipients
    • Custom Headers and Reply-To
    • Metadata
    • Tags
    • Route Selection
    • File Attachments
  • 4. Response
  • Next Steps
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP
PHP