Skip to main content

Getting started

Laravel SMS sends text messages and one-time passwords through several SMS gateways from one Sms facade. You switch gateways in config, get structured results from every send, and can register your own drivers.

Requirements​

  • PHP 8.1 or later
  • A Laravel application

Installation​

Install with Composer:

composer require shabayek/laravel-sms

The service provider and the Sms facade alias are registered automatically through Laravel package discovery.

Publish the config​

php artisan vendor:publish --provider="Shabayek\Sms\Providers\SmsServiceProvider"

or by tag:

php artisan vendor:publish --tag=laravel-sms

This creates config/sms.php.

Choose a gateway​

Choose what gateway you would like to use for your application. Then make that as default driver so that you don't have to specify that everywhere. But, you can also use multiple gateways in a project.

'default' => 'smseg',

Then fill the credentials for that gateway in your .env file:

SMS_CONNECTION=smseg
SMS_USERNAME=username
SMS_PASSWORD=password
SMS_SENDER_ID=sender
SMS_SERVICE=normal

Some gateways need extra settings. See Supported gateways for the connection names and the settings each one reads.

Quick start​

use Shabayek\Sms\Facade\Sms;

$result = Sms::send('0120000000', 'Hello world');

if (! $result['success']) {
logger()->warning('SMS not sent', $result['provider']);
}

$code = Sms::sendOtp('0120000000'); // the code that was sent, or null if it wasn't sent

// Later, compare the code the user typed with the one you stored:
$valid = Sms::verify('0120000000', $request->input('otp'), $storedCode);

Next steps: