🚀 How to Send OTPs, Notifications & DLT SMS in Laravel Using Fast2SMS

Table of contents

SMS is still one of the most reliable channels to reach users instantly. Whether it’s OTP verification, marketing messages, or system alerts, SMS ensures high visibility.
Manually integrating Fast2SMS can be tedious—API payloads, handling templates, and ensuring compliance with DLT. That’s why I built laravel-fast2sms
, a package that lets you:
✅ Send Quick SMS, OTP, and DLT messages
✅ Integrate with queues & scheduling
✅ Monitor wallet balance
✅ Use as a Laravel Notification channel
In this tutorial, we’ll set up the package, send different SMS types, and explore advanced features like queueing & notifications.
🛠️ Requirements
PHP 8.3+
Laravel 12+
Fast2SMS account with API key
⚡ Step 1: Install the Package
composer require itxshakil/laravel-fast2sms
Supports Laravel auto-discovery (no manual provider registration needed).
⚙️ Step 2: Configure Fast2SMS
Publish the config file:
php artisan vendor:publish --tag=fast2sms-config
Update .env
:
FAST2SMS_API_KEY="YOUR_API_KEY"
FAST2SMS_DEFAULT_SENDER_ID="FSTSMS"
FAST2SMS_DEFAULT_ROUTE="dlt"
📤 Step 3: Sending SMS
1. Quick SMS
use Shakil\Fast2sms\Facades\Fast2sms;
use Shakil\Fast2sms\Enums\SmsLanguage;
Fast2sms::quick('9999999999', 'Hello, this is a Quick SMS!');
Fast2sms::quick('9999999999', 'नमस्ते! यह एक क्विक एसएमएस है।', SmsLanguage::UNICODE);
2. DLT SMS
use Shakil\Fast2sms\Facades\Fast2sms;
Fast2sms::dlt(
numbers: '9999999999',
templateId: 'YOUR_TEMPLATE_ID',
variablesValues: ['John Doe'],
senderId: 'YOUR_SENDER_ID'
);
3. OTP SMS
use Shakil\Fast2sms\Facades\Fast2sms;
Fast2sms::otp('9999999999', '123456');
4. Fluent Interface
use Shakil\Fast2sms\Facades\Fast2sms;
use Shakil\Fast2sms\Enums\SmsRoute;
Fast2sms::to('9999999999')
->route(SmsRoute::DLT)
->senderId('YOUR_SENDER_ID')
->templateId('YOUR_TEMPLATE_ID')
->variables(['John Doe'])
->send();
📦 Step 4: Extra Features
✅ Check Wallet Balance
$response = Fast2sms::checkBalance();
if ($response->success()) {
echo "Wallet Balance: {$response->balance}\n";
echo "SMS Count: {$response->smsCount}\n";
}
✅ Queueing SMS
Supports Laravel’s job queues:
// Queue a Quick SMS
Fast2sms::quickQueue('9999999999', 'Hello from queue!');
// Queue a DLT SMS
Fast2sms::dltQueue(
numbers: '9999999999',
templateId: 'YOUR_TEMPLATE_ID',
variablesValues: ['John Doe'],
senderId: 'YOUR_SENDER_ID'
);
// Queue an OTP SMS
Fast2sms::otpQueue('9999999999', '123456');
Advanced Queue Options:
Fast2sms::to('9999999999')
->message('Test message')
->onConnection('redis')
->onQueue('sms')
->delay(now()->addMinutes(10))
->queue();
✅ Notifications Channel
Integrate SMS into Laravel’s Notification system:
use Illuminate\Notifications\Notification;
use Shakil\Fast2sms\Facades\Fast2sms;
use Shakil\Fast2sms\Enums\SmsRoute;
class LowSmsBalanceNotification extends Notification
{
public function __construct(
protected float $balance,
protected float $threshold
) {}
public function via($notifiable) {
return ['fast2sms'];
}
public function toFast2sms($notifiable) {
return Fast2sms::to($notifiable->phone)
->message("Low SMS balance: {$this->balance}. Threshold: {$this->threshold}.")
->route(SmsRoute::QUICK)
->send();
}
}
Usage:
Notification::route('fast2sms', '9999999999')
->notify(new LowSmsBalanceNotification(500, 1000));
⚠️ Error Handling
use Shakil\Fast2sms\Exceptions\Fast2smsException;
try {
Fast2sms::quick('9999999999', 'Hello World');
} catch (Fast2smsException $e) {
logger()->error("SMS failed: " . $e->getMessage());
}
🎯 Why Use laravel-fast2sms
?
🚀 Fluent, Laravel-style API
🎯 Supports Quick, DLT, OTP SMS
⏳ Queue & scheduling support
🔒 DLT-compliant templates
📡 Check balance & monitor thresholds
📱 Works with Laravel Notifications
🎉 Conclusion
With laravel-fast2sms
, you can integrate Fast2SMS into Laravel in just minutes—sending OTPs, notifications, or bulk SMS with queue support and balance monitoring.
👉 Try it today: Laravel Fast2SMS on GitHub
⭐ Don’t forget to star the repo if you find it useful!
Subscribe to my newsletter
Read articles from Shakil Alam directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
