renderbit / laravel-sms
Framework-agnostic PHP library for sending SMS via Renderbit, with Laravel support.
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- mockery/mockery: ^1.0
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0|^12.0
This package is auto-updated.
Last update: 2026-06-26 21:09:11 UTC
README
A Laravel package to send transactional SMS messages through supported SMS gateways. Built with simplicity and robustness in mind.
๐ Features
- Simple API to send SMS via Facade or dependency injection
- API-based architecture โ works with any SMS gateway
- Template variable substitution (
{{ name }}placeholders) - Configurable query parameters, number field, and message field
- Disable SMS in non-production environments via config
- Laravel-native configuration, logging, and service provider
- PHP 8.1+ with Guzzle HTTP client
๐ฆ Installation
composer require renderbit/laravel-sms
Laravel auto-discovers the service provider. No manual registration needed.
๐ Configuration
Publish the configuration file:
php artisan vendor:publish --provider="Renderbit\Sms\SmsServiceProvider" --tag=config
This will publish config/sms.php. Example contents:
return [ 'enabled' => env('SMS_ENABLED', false), 'url' => env('SMS_API_URL', 'http://182.18.143.11/api/mt/SendSMS?'), '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_ENABLED=true SMS_USER= SMS_PASSWORD= SMS_SENDER_ID='IEMUEM' SMS_API_URL='http://182.18.143.11/api/mt/SendSMS?' SMS_NUMBER_FIELD='number' SMS_MESSAGE_FIELD='text'
Note: SMS sending is disabled by default. Set
SMS_ENABLED=truein your.envorsms.enabledin config to enable it.
โ๏ธ Usage
Send an SMS using the Facade or SmsClient:
Using Facade
use Sms; Sms::send('+919999999999', 'Hello, your OTP is 123456');
Using Dependency Injection
use Renderbit\Sms\SmsClient; class NotificationService { public function __construct(protected SmsClient $sms) {} public function notify(string $phone, string $message): bool { return $this->sms->send($phone, $message); } }
Template Variables
You can pass replacement values in a third parameter:
Sms::send('+919999999999', 'Hello {{ name }}, your code is {{ code }}', [ 'name' => 'John', 'code' => 'ABC123', ]); // Sends: "Hello John, your code is ABC123"
โ Return Value
The send method returns true on success (or when SMS is disabled) and false on failure:
if (! Sms::send($phone, $message)) { // Log failure or retry }
Errors are logged automatically via Laravel's logger.
๐งช Testing
Run the package's test suite:
vendor/bin/phpunit
The suite covers unit tests (SmsClient, SmsServiceProvider, Facade) and feature tests (integration through the Laravel container), 22 tests with 51 assertions.
To control SMS behavior in your own tests:
// Disable SMS in tests (sending is logged, not actually sent) config(['sms.enabled' => false]);
๐ Project Structure
config/
sms.php โ Default configuration published to the app
src/
SmsClient.php โ Core SMS sending logic with template substitution
SmsServiceProvider.php โ Laravel service provider (singleton binding, config publish)
Facades/
Sms.php โ Facade accessor for SmsClient
tests/
Unit/
SmsClientTest.php โ 13 tests covering send(), edge cases, and config
SmsServiceProviderTest.php โ Tests for singleton binding, boot, and config publishing
SmsFacadeTest.php โ Tests for facade resolution and call forwarding
Feature/
SmsIntegrationTest.php โ 3 tests for end-to-end flows through the container
๐ค Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change.
๐ License
This package is open-sourced software licensed under the MIT license.