# Send email from Laravel

Install the PHP SDK with Composer, send from a controller or a queued job, and take delivery events on a route in `routes/api.php`. The route verifies `$request->getContent()`, the body as it came.

## Install the PHP SDK

`composer require mailset-app/php` in your app. It asks for PHP 8.1 or later and no other Composer package.

Composer:

```bash
composer require mailset-app/php
```

## Send your first email from Laravel

`new Mailset\Client()` reads `MAILSET_KEY`; in Laravel, bind it once in a service provider and let the container inject it. `send` takes an array with `deliverBy`, and `$sent->id` is the receipt to log against the order.

```php
<?php

require 'vendor/autoload.php';

// Reads MAILSET_KEY from the environment.
$mailset = new Mailset\Client();

$sent = $mailset->send([
    'from' => 'Acme <hello@example.com>',
    'to' => 'ana@example.org',
    'subject' => 'Your Acme code',
    'text' => 'Your code is 123456.',
    'html' => '<p>Your code is <b>123456</b>.</p>',
    'deliverBy' => '10m',
]);

echo $sent->id, ' ', $sent->status, PHP_EOL;
```

## Verify webhooks in routes/api.php

Routes in `routes/api.php` run without Laravel’s CSRF check. This one reads `$request->getContent()`, since `$request->all()` or `->json()` would hand over parsed data instead of the signed bytes, and passes `$request->headers` and `config('services.mailset.hook_secret')` to `Webhooks::verify`. A `MailsetException` answers 401, a `BouncedEvent` with a hard bounce is logged, and `response()->noContent()` marks the batch kept.

```php
<?php

// routes/api.php: a Laravel route for your hook.

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Mailset\Events\BouncedEvent;
use Mailset\MailsetException;
use Mailset\Webhooks;

Route::post('/mailset', function (Request $request) {
    try {
        // The signature covers the body as it came:
        // read it raw. $request->all() or ->json()
        // would lose the bytes it was made over.
        $events = Webhooks::verify(
            $request->getContent(),
            $request->headers,
            config('services.mailset.hook_secret'),
        );
    } catch (MailsetException $error) {
        return response($error->errorCode, 401);
    }
    foreach ($events as $event) {
        if (!$event instanceof BouncedEvent) {
            continue;
        }
        if ($event->bounce->kind === 'hard') {
            $to = $event->recipient;
            logger()->info("Stop writing to {$to}");
        }
    }

    // 2xx once the events are kept. Until then
    // Mailset posts the batch again.
    return response()->noContent();
});
```

In the SDK’s tests: checked by PHPStan against Laravel stand-ins, and run on a fake request.

## Send from your own domain

Your product sends as your own domain either way. What changes is where your team’s mail lives.

- **Sending only.** Your team’s mail stays at Google, Microsoft or wherever it is now. Mailset asks for DKIM, a bounce host and DMARC, and leaves your MX alone. [Send from a domain whose mail stays elsewhere](https://mailset.app/docs/recipes/sending-only)
- **Mailboxes too.** Your team’s mail moves to Mailset, with a real mailbox for every address on the domain and your product’s email on the same bill. [Set up a domain](https://mailset.app/guide/onboarding)

```bash
mailset domains add example.com --sending
mailset domains apply example.com --sending
mailset domains check example.com
mailset keys create --send --domain example.com --from hello@example.com --name "Acme API"
```

## What the PHP SDK’s build checks

Each line comes from the SDK’s own build, which fails when one stops being true.

- **PHP 8.1+**: The oldest its manifest allows (its manifest)
- **No dependencies**: Nothing else to install beside it (its manifest)
- **Typed throughout**: Readonly classes, checked by PHPStan (a test)

## Where to go from here

- [The PHP SDK](https://mailset.app/docs/sdk/php): Every task, from the client’s options to errors and retries.
- [Send email from PHP](https://mailset.app/send-email/php): The PHP guide, with no framework around it.
- [Webhooks](https://mailset.app/docs/webhooks): The events Mailset posts about your product’s email, and how to check a request’s signature.
- [Give sign-in codes a deadline](https://mailset.app/docs/recipes/deadlines): Use deliverBy so a code that would arrive late is never sent.
- [Retry without sending twice](https://mailset.app/docs/recipes/retries): Make a send safe to repeat with an idempotency key or a Message-ID.
- [Handle bounces](https://mailset.app/docs/recipes/bounces): Tell a dead address from a full inbox, and keep your list clean.
- [Send many messages at once](https://mailset.app/docs/recipes/batches): Up to 100 messages a request, each with its own answer.

## Product email on every plan

Both include 10,000 emails a month, your product’s and your team’s together. Past that it’s $0.40 per 1,000 with pay as you go. Every plan and price: https://mailset.app/pricing

## Sending from Laravel, asked and answered

### Does it work with the Mail facade?

It doesn’t register a mail driver. Inject `Mailset\Client` and call `send` where you would send a Mailable.

### Can a queued job send?

Yes. Call `send` in the job’s `handle()` with an `idempotencyKey`, such as the order’s id. If the job runs again after a timeout, Mailset answers the first receipt and nothing goes out twice.

### Where does the hook’s secret go?

`mailset hooks set` prints it once. Put it in `.env` as `MAILSET_HOOK_SECRET` and map it in `config/services.php` under `mailset.hook_secret`, where the route reads it.

### What if my app has no routes/api.php?

Any route outside the `web` middleware group skips the CSRF check. In Laravel 11 and later, `php artisan install:api` creates the file.

## Try it on your own domain

7 days free, with everything on. Make a key, run the example above and watch the receipt come back. Start at https://mailset.app/start

---

© 2026 Intenseloop, Inc. Mailset’s site, docs and guides are copyrighted. You may read them and use their code to build with Mailset. Don’t republish them or use them to build a copy of Mailset. Terms: https://mailset.app/terms#content