symfony/sendinblue-notifier
Symfony Notifier transport for Sendinblue SMS. Configure via DSN (sendinblue://API_KEY@default?sender=PHONE) to send transactional texts using your Sendinblue API key and sender number. Links to Symfony docs, issues, and PRs.
Installation
composer require symfony/sendinblue-notifier
Ensure sendinblue-notifier is enabled in config/services.php:
'sendinblue' => [
'api_key' => env('SENDINBLUE_API_KEY'),
'default_from' => env('SENDINBLUE_DEFAULT_FROM', 'noreply@example.com'),
],
First Use Case: Sending an Email
Inject the SendinblueNotifier service into a controller or command:
use Symfony\Component\Notifier\NotifierInterface;
use Symfony\Component\Notifier\Bridge\Sendinblue\SendinblueTransportFactory;
public function sendWelcomeEmail(NotifierInterface $notifier)
{
$notifier->send(
new Email('Welcome!', 'user@example.com', 'Hello, welcome to our platform!')
);
}
Configuration
SENDINBLUE_API_KEY in .env:
SENDINBLUE_API_KEY=your_api_key_here
config/services.php.Sending Emails
Use the Email message class for transactional emails:
$notifier->send(
new Email('Subject', 'to@example.com', 'Body', ['from@example.com'])
);
Sending SMS
Use the Sms message class:
$notifier->send(
new Sms('Your code is 1234', 'to:+1234567890')
);
Templates
For reusable templates, define them in config/packages/sendinblue_notifier.yaml:
sendinblue_notifier:
templates:
welcome_email:
template_id: 123
variables:
name: '{{ user.name }}'
Then use them in code:
$notifier->send(
new Email('Welcome', 'user@example.com', null, null, null, ['template_id' => 'welcome_email'])
);
Async Sending
Use the AsyncNotifier wrapper for background processing:
$asyncNotifier = new AsyncNotifier($notifier);
$asyncNotifier->send($email);
public function handle(UserRegistered $event)
{
$this->notifier->send(
new Email('Welcome', $event->user->email, 'Welcome content!')
);
}
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$notifier->send($email);
}
try {
$notifier->send($email);
} catch (\Exception $e) {
\Log::error('Sendinblue error: ' . $e->getMessage());
}
API Key Exposure
SENDINBLUE_API_KEY in code. Always use .env.Rate Limits
TooManyRequestsHttpException gracefully:
try {
$notifier->send($email);
} catch (\Symfony\Component\Notifier\Exception\TooManyRequestsHttpException $e) {
// Retry later or queue the email
}
Template IDs
config match those in Sendinblue’s dashboard. Mismatches will fail silently.Async Delays
AsyncNotifier only for non-critical emails.SENDINBLUE_DEBUG=true in .env to log raw API responses:
SENDINBLUE_DEBUG=true
try-catch to inspect HttpException details for failed requests.Custom Transports
Extend SendinblueTransport to add custom logic (e.g., retry logic):
class CustomSendinblueTransport extends SendinblueTransport
{
protected function doSend(Message $message): void
{
// Custom logic before sending
parent::doSend($message);
}
}
Register it in config/packages/sendinblue_notifier.yaml:
sendinblue_notifier:
transport: App\Transport\CustomSendinblueTransport
Event Listeners
Subscribe to NotifierEvent to intercept sends:
$notifier->on('send', function (NotifierEvent $event) {
if ($event->getMessage() instanceof Email) {
// Modify or log the email
}
});
Webhook Validation Validate Sendinblue webhook signatures if using inbound APIs:
use Symfony\Component\Notifier\Bridge\Sendinblue\WebhookValidator;
$validator = new WebhookValidator('your_webhook_secret');
if ($validator->validate($request->getContent(), $request->headers->get('X-Signature'))) {
// Process webhook
}
from address per message:
new Email('Subject', 'to@example.com', 'Body', ['custom@example.com'])
Email constructor’s replyTo and bcc parameters:
new Email('Subject', 'to@example.com', 'Body', null, null, null, ['reply_to' => 'support@example.com'])
How can I help you explore Laravel packages today?