A Laravel package to send transactional SMS messages through supported SMS gateways. Built with simplicity, scalability, and performance in mind.
- Simple API to send SMS
- Support for multiple providers (via api-based architecture)
- Queue-friendly and retry-safe
- Customizable sender name and API URL
- Laravel-native configuration and logging
- Facade & dependency injection support
Install via Composer:
composer require renderbit/laravel-sms
Publish the configuration file:
php artisan vendor:publish --tag=sms-config
This will publish config/sms.php
.
Example config/sms.php
:
return return [
'url' => env('SMS_API_URL', '<default-preconfigured-url>'),
'query_params' => [
'user' => env('SMS_USER'),
'password' => env('SMS_PASSWORD'),
'senderid' => env('SMS_SENDER_ID', 'IEMUEM'),
'channel' => 'trans',
'DCS' => 0,
'flashsms' => 0,
'route' => '1'
],
'number_field' => env('SMS_NUMBER_FIELD', 'number'),
'message_field' => env('SMS_MESSAGE_FIELD', 'text'),
];;
Update your .env
file:
SMS_USER=
SMS_PASSWORD=
SMS_SENDER_ID='IEMUEM'
SMS_API_URL='http://1.1.1.1/api/SendSMS?'
SMS_NUMBER_FIELD='number'
SMS_MESSAGE_FIELD='text'
You can send an SMS using the facade or the SmsClient
class:
use Sms;
Sms::send('+919999999999', 'Hello, your OTP is 123456');
use Renderbit\Sms\SmsClient;
class NotificationService
{
public function __construct(protected SmsClient $sms) {}
public function notify($phone, $message)
{
$this->sms->send($phone, $message);
}
}
The send
method returns a bool
:
$success = Sms::send($phoneNumber, $message);
if (!$success) {
// Log failure or retry
}
To fake SMS sending during tests:
Sms::shouldReceive('send')
->once()
->with('+919999999999', 'Test message')
->andReturn(true);
SmsClient
: Main entry point, handles sms sending logic.Facades\Sms
: Facade accessor for SmsClient class.config\sms
: Default configs that can be overridden after publishing.SmsServiceProvider
: Auto-discovery and binding.
Pull requests are welcome! For major changes, please open an issue first to discuss what you’d like to change.
This package is open-sourced software licensed under the MIT license.
Would you like me to initialize this as a README.md
file inside your package or also help with directory scaffolding like src/SmsClient.php
, Contracts
, etc.?