This documentation is for version 3.12.2 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($account_sid, $auth_token);
$message = $client->account->messages->sendMessage(
'+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', // Call 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 :class:`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: :ref:`usage-twiml`
There are two ways to install twilio-php: via the PEAR installer, or by downloading the source.
Use the Makefile
in the repo's top
pear channel-discover twilio.github.com/pear
pear install twilio/Services_Twilio
If you aren't using PEAR, download the source (.zip), which includes all the dependencies.
.. toctree:: :maxdepth: 2 :glob: usage/rest usage/rest/*
.. toctree:: :maxdepth: 1 usage/twiml usage/validation usage/token-generation faq/
.. toctree:: :maxdepth: 3 :glob: 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 support team at help@twilio.com.
The unit tests depend on Mockery and PHPUnit. First, 'discover' all the necessary PEAR channels:
make test-install
After installation, run the tests with :data:`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.
make docs-install
Once you have those installed, making the docs is easy.
make docs