A Laravel package to send transactional SMS messages through supported SMS gateways. Built with simplicity and robustness in mind.
- 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
composer require renderbit/laravel-smsLaravel auto-discovers the service provider. No manual registration needed.
Publish the configuration file:
php artisan vendor:publish --provider="Renderbit\Sms\SmsServiceProvider" --tag=configThis 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.
Send an SMS using the Facade or SmsClient:
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(string $phone, string $message): bool
{
return $this->sms->send($phone, $message);
}
}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"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.
Run the package's test suite:
vendor/bin/phpunitThe 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]);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
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.