1. Go to this page and download the library: Download twilio/sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
twilio / sdk example snippets
// Send an SMS using Twilio's REST API and PHP
// Required if your environment does not handle autoloading
Twilio\Rest\Client($sid, $token);
// Use the Client to make requests to the Twilio REST API
$client->messages->create(
// The number you'd like to send the message to
'+15558675309',
[
// A Twilio phone number you purchased at https://console.twilio.com
'from' => '+15017250604',
// The body of the text message you'd like to send
'body' => "Hey Jenny! Good luck on the bar exam!"
]
);
// Require the bundled autoload file - the path may need to change
// based on where you downloaded and unzipped the SDK
ient($sid, $token);
// Use the Client to make requests to the Twilio REST API
$client->messages->create(
// The number you'd like to send the message to
'+15558675309',
[
// A Twilio phone number you purchased at https://console.twilio.com
'from' => '+15017250604',
// The body of the text message you'd like to send
'body' => "Hey Jenny! Good luck on the bar exam!"
]
);
$sid = "ACXXXXXX";
$token = "YYYYYY";
$client = new Twilio\Rest\Client($sid, $token);
// Read TwiML at this URL when a call connects (hold music)
$call = $client->calls->create(
'8881231234',
// Call this number
'9991231234',
// From a valid Twilio number
[
'url' => 'https://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient'
]
);
= "ACXXXXXX";
$token = "YYYYYY";
$client = new Twilio\Rest\Client($sid, $token);
// Get an object using its SID. If you do not have a SID,
// check out the list resource examples on this page
$call = $client->calls("CA42ed11f93dc08b952027ffbc406d0868")->fetch();
print $call->to;
= "ACXXXXXX";
$token = "YYYYYY";
$client = new Twilio\Rest\Client($sid, $token);
$limit = 5;
$pageSize = 2;
// Read - fetches all messages eagerly and returns as a list
$messageList = $client->messages->read([], $limit);
foreach ($messageList as $msg) {
print($msg->sid);
}
// Stream - returns an iterator of 'pageSize' messages at a time and lazily retrieves pages until 'limit' messages
$messageStream = $client->messages->stream([], $limit, $pageSize);
foreach ($messageStream as $msg) {
print($msg->sid);
}
// Page - get the a single page by passing pageSize, pageToken and pageNumber
$messagePage = $client->messages->page([], $pageSize);
$nextPageData = $messagePage->nextPage(); // this will return data of next page
foreach ($messagePage as $msg) {
print($msg->sid);
}
= "ACXXXXXX";
$token = "YYYYYY";
$client = new Twilio\Rest\Client($sid, $token);
// Loop over the list of calls and print a property from each one
foreach ($client->calls->read() as $call) {
print $call->direction;
}
Twilio\Exceptions\ConfigurationException;
use Twilio\Rest\Client;
$sid = "ACXXXXXX";
$token = "YYYYYY";
// Attempt to create a new Client, but your credentials may contain a typo
try {
$client = new Twilio\Rest\Client($sid, $token);
} catch (ConfigurationException $e) {
// You can `catch` the exception, and perform any recovery method of your choice
print $e->getCode();
}
$call = $client->account->calls
->get("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
print $call->to;