Skip to content
All posts

Laravel 11: Send Emails with the Brevo API Without SMTP

By Tom Jamon2 min read

When working with Laravel, the most common way to send emails through Brevo is by configuring an SMTP server. However, Brevo also provides a transactional API that offers several advantages:

  • No SMTP configuration required
  • Improved reliability
  • Faster email delivery
  • Native support for Brevo templates
  • Event tracking (opens, clicks, bounces, etc.)

In this article, we'll see how to integrate Brevo as a mail transport in Laravel 11 using its API.

Installing the Required Packages

Start by installing the Symfony Brevo mailer transport and the required HTTP client:

composer require symfony/brevo-mailer
composer require symfony/http-client

Creating a Brevo API Key

From your Brevo dashboard:

  1. Navigate to SMTP & API
  2. Open the API Keys tab
  3. Create a new transactional API key

You should receive a key similar to:

xkeysib-xxxxxxxxxxxxxxxxxxxxxxxx

Laravel Configuration

Add your API key to your .env file:

MAIL_MAILER=brevo

BREVO_API_KEY=xkeysib-xxxxxxxxxxxxxxxxxxxxxxxx

MAIL_FROM_ADDRESS=noreply@yourdomain.com
MAIL_FROM_NAME="${APP_NAME}"

Then update config/services.php:

return [

    // ...

    'brevo' => [
        'key' => env('BREVO_API_KEY'),
    ],

];

Registering the Brevo Mail Transport

Add a new mailer to config/mail.php:

'brevo' => [
    'transport' => 'brevo',
],

Laravel does not natively recognize the Brevo transport, so it must be registered manually.

In AppServiceProvider.php:

use Illuminate\Support\Facades\Mail;
use Symfony\Component\Mailer\Bridge\Brevo\Transport\BrevoTransportFactory;
use Symfony\Component\Mailer\Transport\Dsn;

public function boot(): void
{
    Mail::extend('brevo', function () {
        return (new BrevoTransportFactory())->create(
            new Dsn(
                'brevo+api',
                'default',
                config('services.brevo.key')
            )
        );
    });
}

Clearing Laravel Cache

After updating the configuration, clear Laravel's cache:

php artisan optimize:clear

Sending a Test Email

You can now send emails as usual:

use Illuminate\Support\Facades\Mail;

Mail::raw('Brevo API test', function ($message) {
    $message->to('contact@example.com')
        ->subject('Brevo Test');
});

Or with a Mailable:

Mail::to($user)->send(new WelcomeMail());

No additional changes are required in your application code.

Common Errors

Unsupported mail transport [brevo]

The transport has not been registered correctly in AppServiceProvider, or the symfony/brevo-mailer package is missing.

User is not set

The Dsn constructor is misconfigured. The API key must be passed as the third argument.

You cannot use AbstractHttpTransport as the HttpClient component is not installed

The following package is missing:

composer require symfony/http-client

Conclusion

Using Brevo through its API allows you to keep the full Laravel mail ecosystem while benefiting from the performance and features of Brevo's transactional email platform.

Once configured, your Mailables, Notifications, and queued emails continue to work exactly as they would with SMTP, without requiring any changes to your business logic.

Share this post