Laravel package

Send SMS and OTP codes from Laravel in Morocco

envoisms/laravel-otp is EnvoiSMS.ma's official Laravel package: a notification channel and a facade for sending SMS and OTP codes, built on the envoisms/envoisms-php SDK. One Composer command, two lines in .env, and your Laravel notifications go out as SMS.

composer require envoisms/laravel-otp
# 1. Installer le package officiel composer require envoisms/laravel-otp # 2. .env ENVOISMS_API_KEY=your_api_key_here ENVOISMS_FROM=MonBusiness # 3. (optionnel) config/services.php 'envoisms' => [ 'api_key' => env('ENVOISMS_API_KEY'), 'from' => env('ENVOISMS_FROM', 'EnvoiSMS'), ],
● Routes locales MarocIAM • Inwi • Orange
https://api.envoisms.ma/v1
Local Routes
Maroc Telecom (IAM) • Inwi • Orange
Verified DLR Receipts
HMAC-SHA256 Signed
Clear MAD Pricing
dès 0,60 MAD/SMS • 5 MAD offerts

Install and configure

Install the package with composer require envoisms/laravel-otp, then add your API key and default sender to .env. The configuration can also live in config/services.php under the envoisms key.

  • ENVOISMS_API_KEY=your_api_key
  • ENVOISMS_FROM=MyBusiness (your validated Sender ID)
  • config/services.php: 'envoisms' => ['api_key' => env('ENVOISMS_API_KEY'), 'from' => env('ENVOISMS_FROM', 'EnvoiSMS')]

A Laravel notification channel

Your notification returns EnvoiSMSChannel::class from via() and builds an EnvoiSMSMessage in toEnvoiSMS(). For a one-time code: ->asOtp(brand: 'MyApp', codeLength: 6, expiry: 600). The recipient is any model with a phone attribute or a routeNotificationForEnvoiSMS() method; sending stays a plain $user->notify(new SendOtpNotification()).

  • use EnvoiSMS\Laravel\EnvoiSMSChannel;
  • use EnvoiSMS\Laravel\Messages\EnvoiSMSMessage;
  • Every send carries an Idempotency-Key (from the PHP SDK): a queued notification that is retried never bills twice

Plain-text notifications: orders, reminders, alerts

For an order status or a reminder: ->content("Hello …, your order #… has shipped.")->from('MyBusiness'). The channel defaults to SMS, the right choice for any ordinary text — even to a customer who uses WhatsApp. ->channel('whatsapp') sends from your own connected WhatsApp Business number: without one the API answers 403 WHATSAPP_NOT_CONNECTED, and free text outside the 24-hour customer window answers 400 OUT_OF_24H_WINDOW. Nothing is charged in either case.

  • ->from() takes a validated Sender ID; omit it for the account default
  • A one-time code on WhatsApp: ->asOtp(...)->channel('whatsapp'), through EnvoiSMS's shared sender, no connection needed

The facade: send, then check an OTP

Without a notification, the EnvoiSMS facade sends the code and checks it. EnvoiSMS::sendOtp(['to' => '+212600000000', 'brand' => 'MyApp']) returns a session_id; EnvoiSMS::checkOtp(sessionId: $response['session_id'], code: '123456') returns verified as true when the code is right. The code is generated, sent and expired on EnvoiSMS's side: your application never stores it.

  • use EnvoiSMS\Laravel\Facades\EnvoiSMS;
  • Underlying endpoints: POST /v1/verify/send and POST /v1/verify/check
  • MIT licence, source at github.com/envoisms/laravel-otp

Everything you need to know about Laravel package.

What's the difference between envoisms/laravel-otp and envoisms/envoisms-php?
envoisms/envoisms-php is the PHP SDK, usable in any project. envoisms/laravel-otp builds on it and adds what is specific to Laravel: the notification channel, the EnvoiSMSMessage message and the EnvoiSMS facade.
Can I queue my SMS notifications?
Yes. Every send carries an Idempotency-Key supplied by the PHP SDK: if a notification job is retried after a failure or a timeout, the message is neither sent nor billed a second time.
How do I send an OTP code on WhatsApp from Laravel?
->asOtp(brand: 'MyApp')->channel('whatsapp'). The code goes through EnvoiSMS's shared sender: you don't need to connect your own WhatsApp number.
How do I test without sending real SMS?
Put an env_test_ sandbox key in ENVOISMS_API_KEY: the whole sending path is replayed — validation, pricing, webhooks — without delivering or debiting anything.

Ready to integrate with Laravel package?

Create your account in under 2 minutes. Get 5 MAD of free credit instantly to test the API.