1. Go to this page and download the library: Download openbackend/nepali-sms library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use OpenBackend\NepaliSms\Facades\NepaliSms;
// Send SMS using default gateway
NepaliSms::to('9841234567')
->message('Hello from Nepal!')
->send();
// Send SMS using specific gateway
NepaliSms::gateway('sparrow')
->to('9841234567')
->message('Hello from Sparrow!')
->send();
$recipients = ['9841234567', '9851234567', '9861234567'];
NepaliSms::to($recipients)
->message('Bulk message to all recipients')
->send();
// Generate and send OTP
$otp = NepaliSms::generateOtp('9841234567');
// Verify OTP
$isValid = NepaliSms::verifyOtp('9841234567', '123456');
if ($isValid) {
// OTP is valid
} else {
// Invalid or expired OTP
}
// Create a template
NepaliSms::createTemplate('welcome', 'Welcome {name} to our platform!');
// Send using template
NepaliSms::to('9841234567')
->template('welcome', ['name' => 'John'])
->send();
// Send SMS asynchronously
NepaliSms::to('9841234567')
->message('This will be sent via queue')
->queue();
// Send with delay
NepaliSms::to('9841234567')
->message('This will be sent after 5 minutes')
->delay(now()->addMinutes(5))
->queue();
php artisan make:notification WelcomeMessage
use OpenBackend\NepaliSms\Channels\NepaliSmsChannel;
use OpenBackend\NepaliSms\Messages\NepaliSmsMessage;
class WelcomeMessage extends Notification
{
public function via($notifiable)
{
return [NepaliSmsChannel::class];
}
public function toNepaliSms($notifiable)
{
return NepaliSmsMessage::create()
->message('Welcome to our platform!')
->gateway('sparrow');
}
}
$user->notify(new WelcomeMessage());
$message = NepaliSms::to('9841234567')
->message('Track this message')
->send();
// Check delivery status
$status = NepaliSms::getDeliveryStatus($message->id);
// Get detailed delivery report
$report = NepaliSms::getDeliveryReport($message->id);
// Get SMS statistics for today
$stats = NepaliSms::getStatistics();
// Get statistics for specific date range
$stats = NepaliSms::getStatistics(
from: now()->subDays(7),
to: now()
);
// Get gateway-wise statistics
$gatewayStats = NepaliSms::getGatewayStatistics('sparrow');
// Check if user can send SMS
if (NepaliSms::canSendSms('9841234567')) {
NepaliSms::to('9841234567')
->message('Rate limited message')
->send();
} else {
// Rate limit exceeded
}
// Configure multiple gateways with priority
NepaliSms::gateways(['sparrow', 'ebeema', 'easysms'])
->to('9841234567')
->message('This will try multiple gateways if one fails')
->send();
Event::listen(MessageSent::class, function ($event) {
Log::info('SMS sent successfully', [
'to' => $event->message->to,
'gateway' => $event->message->gateway,
'id' => $event->message->id,
]);
});