Easily integrate multiple SMS gateways into your Laravel application with a unified API.
- Add the repository to your
composer.json:
"repositories": [
{
"type": "vcs",
"url": "https://gitlab.com/enzaime/sms.git"
}
]- Require the package:
composer require enzaime/smsTwilio Driver:
Requires the Twilio PHP SDK (
twilio/sdk).This package includes it, but if you use Twilio elsewhere, ensure it is installed:
composer require twilio/sdk
Onnorokom Driver:
Requires the PHP SOAP extension. Enable it in your PHP installation:
Ubuntu/Debian:
sudo apt-get install php-soapRedHat/CentOS:
sudo yum install php-soapMac (Homebrew):
brew install php # (SOAP is included by default in most Homebrew PHP builds)php.ini (if needed):
extension=soapAfter installation, restart your web server or PHP-FPM as needed.
Add the following to your .env file:
SMS_DEFAULT_DRIVER=twilio|alpha_bd|onnorokom|log
SMS_USER=onnorokom-user
SMS_PASSWORD=onnorokom-pass
TWILIO_SID=your-twilio-sid
TWILIO_AUTH_TOKEN=your-twilio-auth-token
TWILIO_NUMBER=your-twilio-numberTwilio: Recipient number must be in international format (e.g.,
+8801xxxxxxxxx).
The Log driver is ideal for development and staging. Instead of sending SMS, it logs messages to your Laravel log files.
To use:
- Set in
.env:SMS_DEFAULT_DRIVER=log
- Or specify in code:
EnzSms::driver('log')->send('01xxxxxxxxx', 'This will be logged, not sent');
Check storage/logs/laravel.log for logged SMS messages.
EnzSms::send('01xxxxxxxxx', 'Testing');$sms = new \Enzaime\Sms\SmsService();
$sms->send('01xxxxxxxxx', 'Testing');EnzSms::driver('twilio')->send('+8801xxxxxxxxx', 'Testing');Note:
- If no driver is specified, Bangladeshi numbers use
onnorokomoralpha_bd, foreign numbers usetwilio.
driver(string $name = '')— Set the driver for sending SMS. Returns the SmsService instance for chaining.send(string|array $numberOrList, string $text, string $type = '')— Send SMS to one or multiple numbers.isLocal(string $number)— Check if a number is local (Bangladeshi).getDriver(string $driver = '')— Get the current driver instance.getFallbackDriver()— Get the fallback driver instance.
You can use the SMS channel in your Laravel notifications:
use Illuminate\Notifications\Notification;
class InvoicePaid extends Notification
{
public function via($notifiable)
{
return ['sms'];
}
public function toSms($notifiable)
{
return 'Your invoice has been paid!';
}
}- Register the channel in your
NotificationServiceProviderif needed. - Your notifiable model should have a
mobileorcontact_noproperty, or arouteNotificationForSmsmethod.
To use a custom driver:
EnzSms::driver('custom_driver')->send('01xxxxxxxxx', 'Custom driver test');MIT