How to Send SMS using Twilio in Laravel?

https://www.itsolutionstuff.com/post/how-to-send-sms-using-twilio-in-laravelexample.html

How to Send SMS using Twilio in Laravel?

By Hardik Savani February 17, 2021 Category : LaravelPauseUnmuteLoaded: 2.36%FullscreenVDO.AI

Hi,

In this example, i will show you send sms using twilio in laravel. step by step explain laravel - twilio sms notifications. This post will give you simple example of laravel sms notification twilio. you'll learn laravel send sms to mobile with twilio.

In this example, i will give you very simple example to sending sms using twilio api in laravel app. you can easily use this code in laravel 6, laravel 7, laravel 8 and laravel 9 app.

let's follow bellow steps:

Step 1: Install Laravel

first of all we need to get fresh Laravel version application using bellow command, So open your terminal OR command prompt and run bellow command:

composer create-project --prefer-dist laravel/laravel blog

Step 2: Create Twilio Account

First you need to create and add phone number. then you can easily get account SID, Token and Number.

Create Account from here: www.twilio.com.

Next add Twilio Phone Number

Next you can get account SID, Token and Number and add on .env file as like bellow:

.env

TWILIO_SID=XXXXXXXXXXXXXXXXXTWILIO_TOKEN=XXXXXXXXXXXXXTWILIO_FROM=+XXXXXXXXXXX

Read Also: Laravel Bail Rule | Stop Validation On First Failure

Step 3: Install twilio/sdk Package

In this step, we need to install twilio/sdk composer package to use twilio api. so let's run bellow command:

Step 4: Create Route

now we will create one route for calling our example, so let's add new route to web.php file as bellow:

routes/web.php

Step 5: Create Controller

in this step, we will create TwilioSMSController and write send sms logic, so let's add new route to web.php file as bellow:

app/Http/Controllers/TwilioSMSController.php

Read Also: Laravel Livewire Sweetalert Example

Now you can run and check.

I hope it can help you...

Last updated

Was this helpful?