Easily integrate multiple SMS gateways into your Laravel application with a unified API.
- Twilio
- AlphaBd
- BulkSmsDhaka
- Log (for local/staging environments)
- 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
Add the following to your .env file:
SMS_DEFAULT_DRIVER=twilio|alpha_bd|bulk_sms_dhaka|log
TWILIO_SID=your-twilio-sid
TWILIO_AUTH_TOKEN=your-twilio-auth-token
TWILIO_NUMBER=your-twilio-number
BULKSMSDHAKA_API_KEY=your-bulksmsdhaka-api-key
BULKSMSDHAKA_CALLER_ID=your-bulksmsdhaka-caller-idTwilio: 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 the default driver (
bulk_sms_dhakaoralpha_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