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