How to send SMS using plivo with laravel
Plivo are provided with a free trial account to experiment with our services. free trial account is given free credits for testing purpose.
The free credits you can go ahead and purchase a number. a number and credits in your account, you are all set to start testing our voice and SMS service.
Register free Plivo account
- Sign up with your email address Register
- You will receive an activation email from Plivo. Activate your account.
- Enter an SMS enabled, the non-VOIP number to complete the phone verification.
Send SMS using plivo with laravel
You will get your Plivo Auth Id and Auth Token on the home screen.

You must have an SMS-enabled Plivo phone number to send messages.

Installation
$ composer require midnite81/plivo
Integration
Service provider
app.php
#config/app.php 'providers' => [ ... Midnite81\Plivo\MessagingServiceProvider::class ... ]; ... 'aliases' => [ ... 'Messaging' => Midnite81\Plivo\Facades\Messaging::class, ... ];
Publish the config and migration files using :
$ php artisan vendor:publish --provider="Midnite81\Plivo\MessagingServiceProvider"
Configuration File
.env
.env update plivo credentials.
#.env PLIVO_AUTH_ID= #auth_idPLIVO_AUTH_TOKEN= #auth_token PLIVO_SOURCE_NUMBER= #default_sms_number //Register Sandbox Numbers
HomeController.php
#app/Http/Controllers/HomeController.php namespace App\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use Midnite81\Plivo\Contracts\Services\Messaging; //added public function sendOtp(Request $request) { $generatedotp = rand(100000,999999); $to = "+919876543210"; $from = "+919876543210"; $message = "Dear Customer,".$generatedotp." is your one-time password (OTP). Thank you, Team Devnote."; $sms = plivo_send_text($to, $message, $from); if(isset($sms['response']['error']) && !empty($sms['response']['error']) ){ return response()->json(['status'=>false ,'message' => $sms['response']['error']], 200); } else { return response()->json(['status'=>true ,'message' => 'Successfully send otp!'], 200); } }
Output : send message
Dear Customer,169016 is your one-time password (OTP).
Thank you,
Team Devnote.