How to send sms using twilio in PHP

In Today’s time every Business is looking for getting leads and staying connected with customers. Sending them promotion or services messages is the best way to retain attention of customers. Sending Bulk SMS has become quite adopted method today in all fields. There are many companies that provide such services. But TWILIO is the most popular of those and used by most of companies for same purpose. Today I am going to show how we can use Trello API in PHP to send SMS to users.

Download Twilio Helper Library

To use Twilio API in PHP we will firstly need to download Twilio helper SDK. Here is direct link to download as zip file or you can download from Github repo . We can also use composer command if we need if we use composer

composer require twilio/sdk

PHP Code for sending using Twilio API

Firstly extract zip file in root folder where your PHP code file will reside.

// Require the bundled autoload file - the path may need to change
// based on where you downloaded and unzipped the SDK
require __DIR__ . '/twilio-php-main/src/Twilio/autoload.php';
// Use below if you used composer to install Twilio Library
//require __DIR__ . '/vendor/autoload.php';
// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;

// Your Account SID and Auth Token from
$token = 'your_auth_token';
//Sender Phone Number and Twilio Phone Number we purchased
$client = new Client($sid, $token);

// Use the client to do fun stuff like send text messages!
    // the number you'd like to send the message tofrom
    $senderphone, //Change this to rec
        // A Twilio phone number you purchased at
        'from' => $from,
        // the body of the text message you'd like to send
        'body' => "Hey Jenny! Good luck on the bar exam!"

In the above code we will need to replace value of variables $sid , $token , $senderphone , and $phone according to our needs . We can get this values from by logging in to your account

We can simply use this code according to our requirements and turn them into function. And use it in various services like Sending OTP or when user registers. Let me know if you have some doubts in comments or face some trouble while implementing this.