In this tutorial, I will teach to how to use our Communications REST API of Twilio to send SMS using the Twilio PHP helper library.
Steps you need to follow:
- Sign up for Twilio and purchase an SMS-enabled phone number.
- Download Twilio PHP helper library using Composer command.
- Send your first SMS.
How to send SMS using Twilio
Create any PHP Application and download Twilio PHP helper library via composer
composer require twilio/sdk
example.php
<?php
require __DIR__ . '/vendor/autoload.php';
use Twilio\Rest\Client;
// Your Account SID and Auth Token from twilio.com/console
$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = 'your_auth_token';
// you need to buy from twilio
$twilio_number = "+15017122661";
$client = new Client($account_sid, $auth_token);
$client->messages->create(
// recipient number
'+15558675310', array(
'from' => $twilio_number,
'body' => 'I sent this message in under 10 minutes!'
)
);
In the example you can replace your sid, token and twilio number it will help you for sending sms using PHP