Skip to main content
This page covers installing the lettr/lettr-php Composer package and configuring the client for your application. If you haven’t already, start with the Introduction for a quick overview of what the SDK provides.

Requirements

  • PHP 8.4 or higher
  • Guzzle HTTP client 7.5+

Install the Package

composer require lettr/lettr-php
The package installs with no additional dependencies beyond Guzzle HTTP client, which it requires for making API requests. If your project doesn’t already have Guzzle, Composer will install it automatically.

Create a Client

Instantiate the Lettr client with your API key:
use Lettr\Lettr;

$lettr = Lettr::client('your-api-key');
The static client() method returns a configured instance ready to interact with the Lettr API. All subsequent method calls use this client for authentication and requests.
Get your API key from the Lettr dashboard. API keys use the lttr_ prefix followed by 64 hexadecimal characters. See API Keys for details on creating and managing keys.

Store API Keys Securely

Never hardcode API keys in your source code. Store them in environment variables or configuration files that are excluded from version control:
// Using environment variables
$lettr = Lettr::client(getenv('LETTR_API_KEY'));

// Using a config file
$config = require __DIR__ . '/config.php';
$lettr = Lettr::client($config['lettr_api_key']);
Committing API keys to version control is a security risk. Always use environment variables or secure configuration management, and add config files containing secrets to .gitignore.

Available Services

The client provides access to all Lettr API resources through dedicated service objects:
$lettr->emails();     // Send emails (HTML, text, templates)
$lettr->domains();    // Manage sending domains
$lettr->templates();  // Manage email templates
$lettr->webhooks();   // View webhook configurations
$lettr->health();     // API health and auth checks
Each service corresponds to a set of API endpoints. For example, $lettr->emails() gives you access to:
  • Sending emails (HTML, text, templates)
  • Building complex emails with the fluent builder
  • Attaching files and configuring tracking options
See Sending Emails for detailed examples of each service.

Verify Installation

Test that everything is configured correctly using the health check endpoints:
// Check API health (no authentication required)
$status = $lettr->health()->check();
echo $status->isHealthy(); // true

// Verify your API key
$auth = $lettr->health()->authCheck();
echo $auth->teamId;
The health()->check() method verifies that the Lettr API is accessible and operational. It doesn’t require authentication, so it’s useful for monitoring and debugging connectivity issues. The health()->authCheck() method validates your API key and returns your team ID. If no exception is thrown, your API key is valid and you’re ready to send emails.

Troubleshooting

Verify that your API key starts with lttr_ and contains 64 hexadecimal characters after the prefix. Check for extra whitespace or newlines when loading from environment variables.
If you see network or transport errors, check your firewall settings. The SDK needs to reach https://app.lettr.com/api. If you’re behind a corporate proxy, you may need to configure Guzzle with proxy settings.
The from address must use a domain that is verified in your Lettr dashboard. See Domain Verification for common issues.
Check your Lettr logs to see if the API accepted the request. If the email was accepted but not delivered, see Delivery Issues for diagnosis steps.

What’s Next