PHP Quickstart: Making an Outgoing Call

To initiate an outgoing phone call, make an HTTP POST request to the Calls resource URI.

    // 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
            '' // 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:

  • First head over to the Twilio website and log into your Twilio Account page. On the Dashboard there is a section labeled "API Credentials". There you will find your Account SID and Auth Token. Copy those values and paste them into the Account SID and Auth Token variables.
  • Next, we populate the phonenumber parameter with our phone number that we validated with Twilio in the previous step.
  • We then instantiate a new client object, set the request method to 'POST', fill in the 'From', 'To' and 'Url' parameters in an associative array, and fire off the request to Twilio!

Call end callback

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.

Next: Access your call logs using our API »