symfony/infobip-notifier
Symfony Notifier integration for Infobip. Send SMS/notifications via Infobip by configuring the INFOBIP_DSN (auth token, host, and sender/from). Part of the Symfony Notifier ecosystem.
Install Dependencies:
composer require symfony/notifier symfony/infobip-notifier
Configure DSN in .env:
INFOBIP_DSN=infobip://YOUR_AUTH_TOKEN@api.infobip.com?from=YourSenderName
YOUR_AUTH_TOKEN with your Infobip API token.api.infobip.com with your Infobip host (e.g., api.sandbox.infobip.com for testing).from is the sender ID (e.g., YourApp).First Use Case: Send an SMS
use Symfony\Component\Notifier\Notifier;
use Symfony\Component\Notifier\Bridge\Infobip\InfobipTransportFactory;
use Symfony\Component\Notifier\Message\SmsMessage;
$notifier = new Notifier([
new InfobipTransportFactory($_ENV['INFOBIP_DSN']),
]);
$message = new SmsMessage('Hello from Laravel!');
$message->to('+1234567890');
$notifier->send($message);
.env setup and Infobip’s DSN documentation.Notifier class with the Infobip transport.$notifier = app(Notifier::class); // If using Laravel's service container
$notifier->send(new SmsMessage('Your OTP: 123456')->to('+1234567890'));
Registered).// app/Listeners/SendWelcomeSms.php
public function handle(Registered $event) {
$notifier = app(Notifier::class);
$notifier->send(new SmsMessage('Welcome!')->to($event->user->phone));
}
// app/Jobs/SendInfobipNotification.php
public function handle() {
$notifier = app(Notifier::class);
$notifier->send($this->message);
}
Message classes to dynamically set recipients/senders.$message = new SmsMessage('Custom message');
$message->to('+1234567890')->from('DynamicSender');
Notifier as a singleton in AppServiceProvider:
public function register() {
$this->app->singleton(Notifier::class, function ($app) {
return new Notifier([
new InfobipTransportFactory($_ENV['INFOBIP_DSN']),
]);
});
}
$notifier = new Notifier([
new InfobipTransportFactory($_ENV['INFOBIP_DSN']),
new MailTransport($_ENV['MAILER_DSN']), // Fallback
]);
TransportTestCase for unit tests:
use Symfony\Component\Notifier\Test\TransportTestCase;
class InfobipTransportTest extends TransportTestCase {
protected function createTransport(): InfobipTransport {
return new InfobipTransport(new InfobipClient('token', 'host'));
}
}
$notifier = new Notifier([...], [
'debug' => true,
]);
DSN Format Sensitivity
from or malformed host) causes silent failures..env:
INFOBIP_DSN=infobip://TOKEN@HOST?from=Sender&scheme=https
TransportException.Infobip API Rate Limits
Symfony Notifier Events
MessageSentEvent.use Symfony\Component\Notifier\EventListener\MessageSentEvent;
public function handle(MessageSentEvent $event) {
event(new NotificationSent($event->getMessage()));
}
Queue Job Failures
SendInfobipNotification) may not retry or log properly.ShouldQueue and HandleFailures traits:
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Bus\Queueable as QueueableTrait;
class SendInfobipNotification implements ShouldQueue {
use Dispatchable, InteractsWithQueue, QueueableTrait, SerializesModels;
}
PHP Version Mismatches
composer require symfony/notifier:^6.4 symfony/infobip-notifier:^6.4
Use Infobip’s Sandbox
api.sandbox.infobip.com before going live to avoid costs.Monitor Deliverability
$notifier->send($message, function ($message, $transport, $failed) {
if ($failed) {
Log::error('Infobip send failed', ['message' => $message]);
}
});
Extend the Transport
class CustomInfobipTransport extends InfobipTransport {
public function __construct(InfobipClient $client, array $options = []) {
parent::__construct($client, $options + ['headers' => ['X-Custom-Header' => 'value']]);
}
}
Laravel Notifications Facade
// app/Facades/Infobip.php
public static function sendSms(string $message, string $to) {
return app(Notifier::class)->send(new SmsMessage($message)->to($to));
}
Environment-Specific DSNs
config('services.infobip.dsn') for environment-specific configs:
// config/services.php
'infobip' => [
'dsn' => env('INFOBIP_DSN'),
'sandbox' => env('APP_ENV') === 'local',
],
Handle Infobip API Errors
InfobipApiException and map to Laravel’s HttpException:
try {
$notifier->send($message);
} catch (InfobipApiException $e) {
throw new HttpException(500, $e->getMessage());
}
Avoid Hardcoding Tokens
How can I help you explore Laravel packages today?