lettr / lettr-php
Lettr PHP SDK - Send emails via Lettr API
Installs: 13
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/lettr/lettr-php
Requires
- php: ^8.4
- guzzlehttp/guzzle: ^7.5
Requires (Dev)
- laravel/pint: ^1.18
- pestphp/pest: ^3.0
- phpstan/phpstan: ^2.0
This package is not auto-updated.
Last update: 2026-01-09 19:48:22 UTC
README
A PHP client library for the Lettr email API.
Requirements
- PHP 8.4 or higher
- Guzzle HTTP client
Installation
composer require lettr/lettr-php
Usage
Basic Usage
use Lettr\Lettr; use Lettr\Dto\SendEmailData; // Create client with your API key $lettr = Lettr::client('your-api-key'); // Send an email using DTO $email = new SendEmailData( from: 'sender@example.com', to: ['recipient@example.com'], subject: 'Hello from Lettr', text: 'Plain text body', html: '<p>HTML body</p>', ); $response = $lettr->emails()->send($email); echo $response->id; // The email ID
Using Array Syntax
You can also create the DTO from an array:
use Lettr\Lettr; use Lettr\Dto\SendEmailData; $lettr = Lettr::client('your-api-key'); $email = SendEmailData::from([ 'from' => 'sender@example.com', 'to' => ['recipient@example.com'], 'subject' => 'Hello from Lettr', 'text' => 'Plain text body', 'html' => '<p>HTML body</p>', ]); $response = $lettr->emails()->send($email);
Property Access
You can access the emails service via method or property:
// Via method $response = $lettr->emails()->send($email); // Via property $response = $lettr->emails->send($email);
Custom Base URL
If you need to use a different API endpoint:
$lettr = Lettr::client('your-api-key', 'https://custom-api.example.com');
API Reference
SendEmailData
| Parameter | Type | Required | Description |
|---|---|---|---|
from |
string | Yes | Sender email address |
to |
array | Yes | Array of recipient email addresses |
subject |
string | Yes | Email subject |
text |
string | No | Plain text body |
html |
string | No | HTML body |
EmailResponse
| Property | Type | Description |
|---|---|---|
id |
string | Unique identifier for the sent email |
Error Handling
The client throws exceptions for API errors:
use Lettr\Lettr; use Lettr\Exceptions\ApiException; use Lettr\Exceptions\TransporterException; try { $response = $lettr->emails()->send($email); } catch (ApiException $e) { // API returned an error response echo $e->getMessage(); } catch (TransporterException $e) { // Network or transport error echo $e->getMessage(); }
Development
Install Dependencies
composer install
Code Style
This project uses Laravel Pint for code style:
composer lint
Static Analysis
This project uses PHPStan at level 8:
composer analyse
Testing
This project uses Pest for testing:
composer test
License
MIT License. See LICENSE for more information.