Laravel SMS Gateway Package for Bangladesh — Laravelbdsms
Sometimes it becomes tough to send SMS using gateway API. Along with this, a project can use several SMS API gateways from different sms gateway providers. At that time, sending message or OTP using different gateways become time consuming work. To solve this problem, I am going to share an exiting package that can reduce of thinking for sending SMS to Bangladeshi mobile users in a same way, though providers API docs are different. You can watch this video if you feel bored to read docs
Official GitHub Repository for this package is
Currently Supporting all Major Laravel Versions:
- Laravel 6.*
- Laravel 7.*
- Laravel 8.*
- Laravel 9.*
- Laravel 10.*
For using this package it is needed to install using composer first. Here is the below package require command for installing package in your laravel project as dependency.
composer require xenon/laravelbdsms
Publish the package
php artisan vendor:publish --provider=Xenon\LaravelBDSms\LaravelBDSmsServiceProvider
Run below command
php artisan config:cache && php artisan migrate
After successful installation, you can now use this package anywhere in your laravel project. Below is a sample code for sending message using DianaHost
Send SMS Using Dynahost
use Xenon\LaravelBDSms\Provider\DianaHost;
use Xenon\LaravelBDSms\Sender;
$sender = Sender::getInstance();
$sender->setProvider(DianaHost::class); //this is demo for Dianahost
$sender->setMobile('017XXYYZZAA');
$sender->setMessage('helloooooooo boss!');
$sender->setConfig(
[
'api_key' => 'your_api_goes_here',
'type' => 'text',
'senderid' => 'sender_id'
]
);
$status = $sender->send();
Send SMS Using SSLCommerz
use Xenon\LaravelBDSms\Provider\Ssl;
use Xenon\LaravelBDSms\Sender;
$sender = Sender::getInstance();
$sender->setProvider(Ssl::class);
$sender->setMobile('017XXYYZZAA');
$sender->setMessage('helloooooooo boss!');
$sender->setConfig(
[
'api_token' => 'api token goes here',
'sid' => 'text',
'csms_id' => 'sender_id'
]
);
$status = $sender->send();
Demo Response SSLCommerz
array:6 [▼
"status" => "response"
"response" => "{"status":"FAILED","status_code":4003,"error_message":"IP Blacklisted"}"
"provider" => "Xenon\LaravelBDSms\Provider\Ssl"
"send_time" => "2021-07-06 08:03:23"
"mobile" => "017XXYYZZAA"
"message" => "helloooooooo boss!"
]
Method Definition
setProvider() : This method is for selecting provider which will used for send sms to Bangladeshi mobile numbers. You can send use several providers such as
i. BulksmsBD
ii. BDbulkSms
iii.SSL
iv. Greenweb
v. Adn
vi. Alpha SMS
vii. Dynahost
etc.
setMobile() : This method is for providing users mobile number such as 017XXXXXXXXX, 018YYYYYYYYY, 019XXXXXXXX etc.
setMessage() : This is used for which message you want to users using this gateway. You can use any kind of permitted words here
setConfig() : This method is the key part for sending message. Because using this package you can set several username/key or other parameter such as sender id, masking name etc.
send() : This is the final method for firing the messaging trigger. After calling this method it will connect to gateway servers and you will get response from server as json. You can make decision according to that decision.
If you find this package helpful, then don’t forget to star at github . Thanks for staying with me. If want to give thanks, then you can knock me at facebook