4.2 KiB
twilio-php
Status
This documentation is for version 3.12.2 of twilio-php.
Quickstart
Send an SMS
// 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;
Make a Call
// 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' );
Generating TwiML
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
Installation
There are two ways to install twilio-php: via the PEAR installer, or by downloading the source.
Via PEAR
Use the Makefile in the repo’s top
pear channel-discover twilio.github.com/pear pear install twilio/Services_Twilio
From Source
If you aren’t using PEAR, download the source (.zip), which includes all the dependencies.
User Guide
REST API
:glob: usage/rest usage/rest/*
TwiML and other utilities
usage/twiml usage/validation usage/token-generation faq/
API Documentation
:glob: api/*
Support and Development
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.
Running the Tests
The unit tests depend on Mockery and PHPUnit. First, ‘discover’ all the necessary PEAR channels:
make test-install
After installation, run the tests with make.
make test
Making the Documentation
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