PHPackages                             lettr/lettr-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. lettr/lettr-laravel

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

lettr/lettr-laravel
===================

Lettr for Laravel - Official Laravel integration for Lettr email API

v1.4.0(1mo ago)5805↑650%MITPHPPHP ^8.4CI passing

Since Jan 23Pushed 1mo agoCompare

[ Source](https://github.com/lettr-com/lettr-laravel)[ Packagist](https://packagist.org/packages/lettr/lettr-laravel)[ Docs](https://lettr.com/)[ RSS](/packages/lettr-lettr-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (18)Versions (38)Used By (0)

Lettr for Laravel
=================

[](#lettr-for-laravel)

[![CI](https://github.com/TOPOL-io/lettr-laravel/actions/workflows/ci.yml/badge.svg)](https://github.com/TOPOL-io/lettr-laravel/actions/workflows/ci.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/d4397073542bd2c651d888467a3f917ae97818aad7b0505d09fbdea3f5a2e6df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c657474722f6c657474722d6c61726176656c2e737667)](https://packagist.org/packages/lettr/lettr-laravel)[![Total Downloads](https://camo.githubusercontent.com/c4c50d8a0c9c945ebe63c4527bda8c652ea8d442b69dcffda73ad17ba8cd8515/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c657474722f6c657474722d6c61726176656c2e737667)](https://packagist.org/packages/lettr/lettr-laravel)[![PHP Version](https://camo.githubusercontent.com/187cc0068c0b02b74fb7852d8c6dc035542f550fbb23a7aa09339766488a195a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c657474722f6c657474722d6c61726176656c2e737667)](https://packagist.org/packages/lettr/lettr-laravel)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

Official Laravel integration for the [Lettr](https://lettr.com) email API.

Requirements
------------

[](#requirements)

- PHP 8.4+
- Laravel 10.x, 11.x, 12.x, or 13.x

Installation
------------

[](#installation)

```
composer require lettr/lettr-laravel
```

Publish the configuration file:

```
php artisan vendor:publish --tag=lettr-config
```

Getting Started
---------------

[](#getting-started)

The easiest way to set up Lettr in your Laravel application is using the interactive init command:

```
php artisan lettr:init
```

This command will guide you through:

- **API Key Configuration** - Automatically adds your Lettr API key to `.env`
- **Mailer Setup** - Configures the Lettr mailer in `config/mail.php`
- **Template Download** - Optionally pulls your email templates as Blade files
- **Code Generation** - Generates type-safe DTOs, Mailables, and template enums
- **Domain Verification** - Checks your sending domain is properly configured

> **Tip:** If you already have a verified sending domain in your [Lettr account](https://app.lettr.com/domains/sending), the init command will automatically configure your `MAIL_FROM_ADDRESS` to match it.

After running `lettr:init`, you're ready to send emails:

```
use Illuminate\Support\Facades\Mail;
use App\Mail\Lettr\WelcomeEmail;

// Using a generated Mailable
Mail::to('user@example.com')->send(new WelcomeEmail($data));

// Or send templates inline
Mail::lettr()->to('user@example.com')->sendTemplate('welcome-email', substitutionData: $data);
```

Manual Setup
------------

[](#manual-setup)

If you prefer to configure manually, add your [Lettr API key](https://app.lettr.com) to your `.env` file:

```
LETTR_API_KEY=your-api-key
```

### Sending Domain

[](#sending-domain)

To send emails through Lettr, you must have a verified sending domain in your [Lettr account](https://app.lettr.com/domains/sending). Your `MAIL_FROM_ADDRESS` (or any "from" address you use) must match a verified domain.

For example, if you've verified `example.com` in Lettr:

```
MAIL_FROM_ADDRESS=hello@example.com
MAIL_FROM_NAME="My App"
```

Emails sent from addresses on unverified domains will be rejected.

Quick Start
-----------

[](#quick-start)

### Using Laravel Mail (Recommended)

[](#using-laravel-mail-recommended)

Add the Lettr mailer to your `config/mail.php`:

```
'mailers' => [
    // ... other mailers

    'lettr' => [
        'transport' => 'lettr',
    ],
],
```

Set as default in `.env`:

```
MAIL_MAILER=lettr
```

Send emails using Laravel's Mail facade:

```
use Illuminate\Support\Facades\Mail;
use App\Mail\WelcomeEmail;

Mail::to('recipient@example.com')->send(new WelcomeEmail());
```

### Using the Lettr Facade Directly

[](#using-the-lettr-facade-directly)

```
use Lettr\Laravel\Facades\Lettr;

$response = Lettr::emails()->send(
    Lettr::emails()->create()
        ->from('sender@example.com', 'Sender Name')
        ->to(['recipient@example.com'])
        ->subject('Hello from Lettr')
        ->html('Hello!This is a test email.')
);

echo $response->requestId; // Request ID for tracking
echo $response->accepted;  // Number of accepted recipients
```

Laravel Mail Integration
------------------------

[](#laravel-mail-integration)

### With Mailable Classes

[](#with-mailable-classes)

```
use Illuminate\Support\Facades\Mail;
use App\Mail\OrderConfirmation;

// Send using Mailable
Mail::to('customer@example.com')
    ->cc('sales@example.com')
    ->bcc('records@example.com')
    ->send(new OrderConfirmation($order));
```

### With Raw Content

[](#with-raw-content)

```
Mail::raw('Plain text email content', function ($message) {
    $message->to('recipient@example.com')
            ->subject('Quick Update');
});
```

### With Views

[](#with-views)

```
Mail::send('emails.welcome', ['user' => $user], function ($message) {
    $message->to('recipient@example.com')
            ->subject('Welcome!');
});
```

### Multiple Mail Drivers

[](#multiple-mail-drivers)

Use Lettr for specific emails while keeping another default:

```
// Use Lettr for this specific email
Mail::mailer('lettr')
    ->to('recipient@example.com')
    ->send(new TransactionalEmail());

// Uses default mailer
Mail::to('other@example.com')
    ->send(new MarketingEmail());
```

Using Lettr Templates with Mailables
------------------------------------

[](#using-lettr-templates-with-mailables)

Instead of using Blade views, you can send emails using Lettr templates directly. Extend the `LettrMailable` class:

```
