How to Make a Phone Call Using Twilio in a PHP Application on Azure

The following example shows you how you can use Twilio to make a call from a PHP web page hosted in Azure. The resulting application will prompt the user for phone call values, as shown in the following screen shot.

Azure Call Form Using Twilio and PHP

You'll need to do the following to use the code in this topic:

  1. Acquire a Twilio account and authentication token from your Twilio Console. To get started with Twilio, evaluate pricing at You can sign up for a trial account at
  2. Obtain the Twilio library for PHP or install it as a PEAR package. For more information, see the readme file.
  3. Install the Azure SDK for PHP.

Create a web form for making a call

The following HTML code shows how to build a web page (callform.html) that retrieves user data for making a call:

<!DOCTYPE html>
  <title>Automated call form</title>
  <h1>Automated Call Form</h1>
  <p>Fill in all fields and click <b>Make this call</b>.</p>
  <form action="makecall.php" method="post">
        <td><input name="callTo" size="50" type="text" value=""></td>
        <td><input name="callFrom" size="50" type="text" value=""></td>
        <td>Call message:</td>
        <td><input name="callText" size="100" type="text" value="Hello. This is the call text. Good bye."></td>
        <td colspan="2"><input type="submit" value="Make this call"></td>

Create the code to make the call

The following code shows how to build makecall.php, which is called when the user submits the form displayed by callform.html. The code shown below creates the call message and generates the call. Also, be sure to use your Twilio account and authentication token from the Twilio Console instead of the placeholder values assigned to $sid and $token in the code below.

<head><title>Making call...</title></head>
<p>Your call is being made.</p>

require_once 'path/to/vendor/autoload.php';

$sid   = "your_account_sid";
$token = "your_authentication_token";

$from_number = $_POST['callFrom']; // Calls must be made from a registered Twilio number.
$to_number   = $_POST['callTo'];
$message     = $_POST['callText'];

$client = new Twilio\Rest\Client($sid, $token);

$call = $client->calls->create(
            array('url' =>' . urlencode($message))

echo "Call status: " . $call->status . "<br />";
echo "URI resource: " . $call->uri . "<br />";

In addition to making the call, makecall.php displays some call metadata, as is shown in the image below. For more information about call metadata, see

Azure Call Response Using Twilio and PHP

Run the application

The next step is to deploy your application to Azure Web Apps with Git (though not all the information there is relevant).

Next steps

This code was provided to show you basic functionality using Twilio in PHP on Azure. Before deploying to Azure in production, you may want to add more error handling or other features. For example:

For additional information about Twilio, see

See Also