PHP code example of lettermint / lettermint-php

1. Go to this page and download the library: Download lettermint/lettermint-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lettermint / lettermint-php example snippets


$lettermint = new Lettermint\Lettermint('your-api-token');

$email = Lettermint\Lettermint::email(getenv('LETTERMINT_SENDING_TOKEN'));
$api = Lettermint\Lettermint::api(getenv('LETTERMINT_API_TOKEN'));

$response = $lettermint->email
                       ->from('[email protected]')
                       ->to('[email protected]')
                       ->subject('Hello from Lettermint!')
                       ->text('Hello! This is a test email.')
                       ->send();


$lettermint->email
    ->from('John Doe <[email protected]>')
    ->to('[email protected]', '[email protected]')
    ->cc('[email protected]')
    ->bcc('[email protected]')
    ->replyTo('[email protected]')
    ->subject('Hello world!')
    ->html('<h1>Hello!</h1>')
    ->text('Hello!')
    ->headers(['X-Custom-Header' => 'Value'])
    ->attach('document.pdf', base64_encode($fileContent))
    ->attach('logo.png', base64_encode($logoContent), '[email protected]')
    ->route('my-route-id')
    ->idempotencyKey('unique-request-id-123')
    ->send();

$response = $email->send([
    'from' => '[email protected]',
    'to' => ['[email protected]'],
    'subject' => 'Hello from Lettermint!',
    'text' => 'Hello! This is a test email.',
]);

$response = $email->sendBatch([
    [
        'from' => '[email protected]',
        'to' => ['[email protected]'],
        'subject' => 'First email',
        'text' => 'Hello!',
    ],
    [
        'from' => '[email protected]',
        'to' => ['[email protected]'],
        'subject' => 'Second email',
        'text' => 'Hello again!',
    ],
]);

$lettermint->email
    ->from('[email protected]')
    ->to('[email protected]')
    ->subject('Email with inline image')
    ->html('<p>Here is an image: <img src="cid:[email protected]"></p>')
    ->attach('logo.png', base64_encode($imageContent), '[email protected]')
    ->send();

$response = $lettermint->email
                       ->from('[email protected]')
                       ->to('[email protected]')
                       ->subject('Hello from Lettermint!')
                       ->text('Hello! This is a test email.')
                       ->idempotencyKey('unique-request-id-123')
                       ->send();

$api = Lettermint\Lettermint::api(getenv('LETTERMINT_API_TOKEN'));

$projects = $api->projects->list(['filter[search]' => 'production']);

$project = $api->projects->create([
    'name' => 'Production',
    'smtp_enabled' => false,
]);

$api->domains->verifyDnsRecords('domain-id');

$stats = $api->stats->retrieve([
    'from' => '2026-05-01',
    'to' => '2026-05-09',
]);

$api->suppressions->create([
    'email' => '[email protected]',
    'reason' => 'manual',
    'scope' => 'team',
]);

$api->webhooks->create([
    'route_id' => 'route-id',
    'name' => 'Production webhook',
    'url' => 'https://example.com/lettermint/webhook',
    'events' => ['message.sent', 'message.delivered'],
]);

$email->ping();
$api->ping();
bash
composer