symfony/sendinblue-mailer
Symfony Mailer bridge for Sendinblue (Brevo). Provides a transport to send emails through the Sendinblue API while using Symfony Mailer features and configuration, integrating easily into Symfony apps for transactional and marketing email delivery.
Install the Package
composer require symfony/mailer symfony/sendinblue-mailer
(Note: symfony/mailer is a dependency, so install both.)
Configure in config/mail.php
Add Sendinblue as a transport in Laravel’s mail config:
'transports' => [
'sendinblue' => [
'dsn' => 'sendinblue://default:your_sendinblue_api_key@default',
],
],
(Replace your_sendinblue_api_key with your actual API key from Sendinblue.)
Set Default Transport
In .env:
MAIL_MAILER=sendinblue
First Test Email
use Illuminate\Support\Facades\Mail;
Mail::send([], [], function ($message) {
$message->to('recipient@example.com')
->subject('Test Email')
->text('Hello from Laravel + Sendinblue!');
});
Mail::to('user@example.com')->send(new OrderShipped($order));
(Use Laravel’s Mailable classes for structured emails.)
Mail::to('user@example.com')->later(now()->addMinutes(5))->send(new WelcomeEmail());
(Requires MAIL_MAILER=sendinblue + queue driver configured.)
$message = (new OrderShipped($order))->to('user@example.com');
$message->attach(storage_path('app/invoice.pdf'));
$message->embed(storage_path('app/logo.png'), 'logo_id');
Mail::send('emails.welcome', ['user' => $user], function ($message) {
$message->to($user->email)->subject('Welcome!');
});
Mail::markdown('emails.notification', ['data' => $data])
->to($user->email)
->subject('Your Notification');
$recipients = ['user1@example.com', 'user2@example.com'];
Mail::to($recipients)->send(new Newsletter());
$message = (new OrderConfirmation($order))->to('user@example.com');
$message->sendinblueTemplateId(12345); // Your Sendinblue template ID
Sendinblue automatically tracks opens/clicks. Access data via:
// In an Event Listener
public function handle(UserRegistered $event) {
Mail::to($event->user->email)->send(new WelcomeEmail($event->user));
}
public function test_welcome_email() {
Mail::fake();
$this->actingAs($user)
->post('/register');
Mail::assertSent(WelcomeEmail::class);
}
.env:
SENDINBLUE_API_KEY=sandbox_key_here
API Key Exposure
.env to version control..env or environment variables securely.Rate Limits
Template Mismatches
sendinblueTemplateId matches your Sendinblue template ID.dd($message->getSendinblueTemplateId()).Async Delays
failed_jobs table for stuck emails.HTML vs. Text Parts
Mailable includes both:
public function build() {
$this->subject('Hello')
->html('view.welcome')
->text('plain.welcome');
}
Check Raw Message
$message = (new WelcomeEmail())->to('user@example.com');
dd($message->getSymfonyMessage()->toString());
Enable Symfony Mailer Debug
// In a test or debug route
$mailer = app(\Symfony\Component\Mailer\Mailer::class);
$mailer->getTransport()->getLogger()->setLevel(\Psr\Log\LogLevel::DEBUG);
Sendinblue API Errors
failed_jobs table for exception field.401 Unauthorized: Invalid API key.400 Bad Request: Invalid template ID or recipient.Custom Transport
Extend Symfony’s Transport for custom logic:
use Symfony\Component\Mailer\Transport\AbstractTransport;
class CustomSendinblueTransport extends AbstractTransport {
protected function doSend(Swift_Mime_SimpleMessage $message) {
// Custom logic (e.g., retry failed sends)
}
}
Webhook Handling
Use Laravel’s route:webhook to handle Sendinblue events (e.g., email opens):
Route::post('/sendinblue/webhook', function (Request $request) {
// Validate and process webhook payload
});
Bulk Emails For large campaigns, use Sendinblue’s SMTP Relay or their Transactional API directly.
DSN Format
sendinblue://api_key@defaultDefault vs. Custom Transports
mailer key in .env to switch between transports dynamically:
MAIL_MAILER=sendinblue
MAIL_SENDINBLUE_TRANSPORT=custom_sendinblue
SSL/TLS
Use Laravel Notifications
Combine with Illuminate\Notifications for unified email/SMS logic:
$user->notify(new WelcomeNotification());
Localization Support multiple languages in emails:
$message->subject(__('Welcome!'));
$message->markdown('emails.welcome', ['user' => $user], fn ($m) => $m->locale($user->locale));
Monitor with Laravel Horizon Track email queue performance:
php artisan horizon
Sendinblue SMTP Fallback
If using SMTP, ensure your Laravel mail.php has:
'sendinblue' => [
'transport' => 'smtp',
'host' => 'smtp.sendinblue.com',
'port' => 587,
'encryption' => 'tls',
'auth_mode' => 'login',
'username' => 'your@email.com',
'password' => 'your_sendinblue_smtp_password',
],
How can I help you explore Laravel packages today?