Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

195 lines (128 sloc) 4.694 kB

twilio-php

Status

This documentation is for version 3.5.2 of twilio-php.

Quickstart

Send a 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('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;

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', // Text 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 :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`

Installation

There are two ways to install twilio-php: via the PEAR installer, or by downloading the source.

Via PEAR

pear channel-discover twilio.github.com/pear
pear install twilio/Services_Twilio    # may need to run sudo pear instead

From Source

If you aren't using PEAR, download the source (.zip), which includes all the dependencies.

User Guide

REST API

TwiML and other utilities

API Documentation

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 IRC channel

Running the Tests

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 :data:`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.

pip install Sphinx sphinxcontrib-phpdomain

Once you have those installed, making the docs is easy.

cd docs
make html
Jump to Line
Something went wrong with that request. Please try again.