Invia email da Laravel
Invia tramite il relay SMTP di Brevo o l'SDK PHP registrato come singleton in un service provider, poi controlla la consegna nei log email di Brevo.

Chiedi al tuo agente IA
Usa gli assistenti IA per interagire con il tuo account Brevo in linguaggio naturale.
Before I send email from my Laravel app, check that I have a verified sender and an authenticated sending domain. List what is missing.
Show the delivery, open and click events for my transactional emails in the last 3 days and flag any that did not deliver.
Sola lettura: legge il tuo account Brevo tramite il server Brevo MCP e non modifica nulla.
Come funziona
Invia tramite il relay SMTP di Brevo, oppure registra il client dell'SDK PHP come singleton in un service provider.L'host del relay SMTP è smtp-relay.brevo.com. Le porte 587 e 2525 non sono crittografate, mentre la 465 usa SSL o TLS.
Per SMTP usa una chiave SMTP dalla scheda SMTP, non una chiave API.
Per l'SDK, installa getbrevo/brevo-php con composer require.
Il relay SMTP non supporta l'invio in batch, quindi per i batch usa gli endpoint API.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Brevo\Brevo;
use Brevo\TransactionalEmails\Requests\SendTransacEmailRequest;
use Brevo\TransactionalEmails\Types\SendTransacEmailRequestSender;
use Brevo\TransactionalEmails\Types\SendTransacEmailRequestToItem;
$client = new Brevo(apiKey: 'your-api-key');
$result = $client->transactionalEmails->sendTransacEmail(
new SendTransacEmailRequest([
'subject' => 'Hello from Brevo!',
'htmlContent' => '<html><body><p>Hello,</p><p>This is my first transactional email.</p></body></html>',
'sender' => new SendTransacEmailRequestSender([
'name' => 'Alex from Brevo',
'email' => '[email protected]',
]),
'to' => [
new SendTransacEmailRequestToItem([
'email' => '[email protected]',
'name' => 'John Doe',
]),
],
])
);
echo 'Email sent. Message ID: ' . $result->messageId . PHP_EOL;
composer require getbrevo/brevo-php
// AppServiceProvider.php
use Brevo\Brevo;
public function register(): void
{
$this->app->singleton(Brevo::class, function () {
return new Brevo(apiKey: config('services.brevo.api_key'));
});
}
MAIL_MAILER=smtp
MAIL_HOST=smtp-relay.brevo.com
MAIL_PORT=587
MAIL_USERNAME=your-login@example.com
MAIL_PASSWORD=YOUR_SMTP_KEY
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@yourdomain.com
MAIL_FROM_NAME="My App"
La scheda .env usa il tuo login SMTP e la tua chiave SMTP. La scheda SDK legge una chiave API dalla configurazione. Tieni le chiavi fuori dal codice.
Perché funziona
Email da Laravel con Brevo: i fatti
Relay SMTP. L'host è smtp-relay.brevo.com. Usa le porte 587 o 2525, oppure la porta 465 con crittografia SSL o TLS. Per le connessioni al relay SMTP usa una chiave SMTP, non una chiave API.
API. Invia un'email transazionale con POST https://api.brevo.com/v3/smtp/email e la tua chiave API nell'header api-key.
Piano Free. Il piano Free include 300 invii email al giorno e fino a 100.000 contatti archiviati. Tutti i piani Brevo ti danno accesso alle API RESTful, a SMTP e ai webhook in uscita per le email transazionali.
Hosting in UE. I server di hosting su cui Brevo elabora e archivia i propri database si trovano tutti nell'Unione Europea. Brevo utilizza OVH in Francia e Germania e i dati sono archiviati su Google Cloud in Belgio.