This documentation is for version 3.7.0 of twilio-php.
// Download the library and copy into the folder containing this file.
require('/path/to/twilio-php/Services/Twilio.php');
$account_sid = "ACXXXXXX"; // Your Twilio account sid
$auth_token = "YYYYYY"; // Your Twilio auth token
$client = new Services_Twilio('AC123', '123');
$message = $client->account->sms_messages->create(
'+14085551234', // From a Twilio number in your account
'+12125551234', // Text any number
"Hello monkey!"
);
print $message->sid;
// Download the library and copy into the folder containing this file.
require('/path/to/twilio-php/Services/Twilio.php');
$account_sid = "ACXXXXXX"; // Your Twilio account sid
$auth_token = "YYYYYY"; // Your Twilio auth token
$client = new Services_Twilio($account_sid, $auth_token);
$call = $client->account->calls->create(
'+14085551234', // From a Twilio number in your account
'+12125551234', // Text any number
// Read TwiML at this URL when a call connects (hold music)
'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient'
);
To control phone calls, your application needs to output TwiML. Use Services_Twilio_Twiml
to easily create such responses.
$response = new Services_Twilio_Twiml();
$response->say('Hello');
$response->play('https://api.twilio.com/cowbell.mp3', array("loop" => 5));
print $response;
<?xml version="1.0" encoding="utf-8"?>
<Response>
<Say>Hello</Say>
<Play loop="5">https://api.twilio.com/cowbell.mp3</Play>
<Response>
View more examples of TwiML generation here: usage-twiml
There are two ways to install twilio-php: via the PEAR installer, or by downloading the source.
pear channel-discover twilio.github.com/pear
pear install twilio/Services_Twilio # may need to run sudo pear instead
If you aren't using PEAR, download the source (.zip), which includes all the dependencies.
usage/rest usage/rest/*
usage/twiml usage/validation usage/token-generation faq/
api/*
All development occurs on Github. To check out the source, run
git clone git@github.com:twilio/twilio-php.git
Report bugs using the Github issue tracker.
If you’ve got questions that aren’t answered by this documentation, ask the #twilio IRC channel
The unit tests depend on Mockery and PHPUnit. First, 'discover' all the necessary PEAR channels:
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear channel-discover pear.survivethedeepend.com
pear channel-discover hamcrest.googlecode.com/svn/pear
pear install --alldeps deepend/Mockery
pear install phpunit/PHPUnit
After installation, run the tests with make
make test
Our documentation is written using Sphinx. You'll need to install Sphinx and the Sphinx PHP domain before you can build the docs.
pip install Sphinx sphinxcontrib-phpdomain
Once you have those installed, making the docs is easy.
cd docs
make html