> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lekalao.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel transport

> Send a Laravel application's e-mails through Lekalao, without touching its code.

Your Laravel application keeps its `Mailable` classes and its `Mail::to(...)->send(...)` calls. The transport hands them to Lekalao's transactional API, which sends them with the provider you chose and keeps them in its log: deliveries, bounces, opens, clicks.

## Install

The `lekalao/laravel-transport` package ships with Lekalao, in `packages/laravel-transport`. Laravel 11, 12 or 13, PHP 8.2 or later.

From the application that sends, declare the repository and install it:

```json composer.json theme={null}
{
    "repositories": [
        { "type": "path", "url": "../lekalao/packages/laravel-transport" }
    ],
    "require": {
        "lekalao/laravel-transport": "*"
    }
}
```

```bash theme={null}
composer update lekalao/laravel-transport
```

The service provider is discovered on its own. If the application lives on another machine, copy the folder into its repository or publish it to your private Composer repository.

## Configure

Create a **Read and write** token in Lekalao, then in `config/mail.php`:

```php config/mail.php theme={null}
'mailers' => [
    // …
    'lekalao' => [
        'transport' => 'lekalao-api',
        'endpoint' => env('LEKALAO_URL'),   // https://lekalao.example.com
        'token' => env('LEKALAO_TOKEN'),
    ],
],
```

```bash .env theme={null}
MAIL_MAILER=lekalao
LEKALAO_URL=https://lekalao.example.com
LEKALAO_TOKEN=12|kJ3v8mQ2xP9…
```

<Note>
  The key is called `endpoint`, not `url`: Laravel reads a mailer's `url` key
  as an SMTP connection string.
</Note>

To use Lekalao for some e-mails only, keep your own `MAIL_MAILER` and choose case by case:

```php theme={null}
Mail::mailer('lekalao')->to($order->customer)->send(new OrderConfirmed($order));
```

## What goes through

| Item             |                                                           |
| ---------------- | --------------------------------------------------------- |
| Recipients       | `to`, `cc`, `bcc`.                                        |
| Subject          | As it is.                                                 |
| Body             | The HTML. A text-only message is shown as it was written. |
| Sender, reply-to | As they are. The sender must be allowed by Lekalao.       |
| Attachments      | All of them.                                              |

The e-mail's identifier in Lekalao becomes the `Message-ID` of the message sent, which is how you find it again in the log.

### Choosing the sending provider

Add the `X-Lekalao-Mailer` header with the name of a provider configured in Lekalao:

```php theme={null}
public function headers(): Headers
{
    return new Headers(text: ['X-Lekalao-Mailer' => 'Postmark transactional']);
}
```

## Errors

A refusal from Lekalao (sender not allowed, token revoked, provider failing) comes back as a `Symfony\Component\Mailer\Exception\TransportException` carrying the HTTP code and the reason. Send your e-mails **on a queue** (`ShouldQueue`) so Laravel retries on its own.

The timeout is 15 seconds.
