To initiate an outgoing phone call, make an HTTP POST request to the Calls resource URI.
<?php
// Include the Twilio PHP library
require 'Services/Twilio.php';
// Twilio REST API version
$version = "2010-04-01";
// Set our Account SID and AuthToken
$sid = 'AC123';
$token = 'abcd';
// A phone number you have previously validated with Twilio
$phonenumber = '4151234567';
// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($sid, $token, $version);
try {
// Initiate a new outbound call
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call
'5101234567', // The number of the phone receiving call
'http://demo.twilio.com/welcome/voice/' // The URL Twilio will request when the call is answered
);
echo 'Started call: ' . $call->sid;
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage();
}
Lets look at the details:
By default, your application does not get any notification when a call is complete, if the line is busy, or no one answers. To get notification of call status, include the "StatusCallback" parameter with your REST request.
When the call is complete or if the line is busy or no one answers, Twilio will make a request to the URL you specify in the "StatusCallback" parameter.