renderbit/laravel-sms

Framework-agnostic PHP library for sending SMS via Renderbit, with Laravel support.

Maintainers

Package info

github.com/RenderbitTechnologies/laravel-sms

Homepage

pkg:composer/renderbit/laravel-sms

Statistics

Installs: 745

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.3.0 2026-01-07 08:16 UTC

This package is auto-updated.

Last update: 2026-06-26 21:09:11 UTC


README

Tests Latest Version on Packagist PHP Version Laravel Version License

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=true in your .env or sms.enabled in 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.