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.
You'll need to do the following to use the code in this topic:
The following HTML code shows how to build a web page (callform.html) that retrieves user data for making a call:
<html> <head> <title>Automated call form</title> </head> <body> <h1>Automated Call Form</h1> <p>Fill in all fields and click <b>Make this call</b>.</p> <form action="makecall.php" method="post"> <table> <tr> <td>To:</td> <td><input type="text" size=50 name="callTo" value=""></td> </tr> <tr> <td>From:</td> <td><input type="text" size=50 name="callFrom" value=""></td> </tr> <tr> <td>Call message:</td> <td><input type="text" size=100 name="callText" value="Hello. This is the call text. Good bye." /></td> </tr> <tr> <td colspan=2><input type="submit" value="Make this call"></td> </tr> </table> </form> <br/> </body> </html>
The following code shows how to build a web page (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. (Use your Twilio account and authentication token instead of the placeholder values assigned to $sid and $token in the code below.)
<html> <head><title>Making call...</title></head> <body> <p>Your call is being made.</p> <?php require_once 'Services/Twilio.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 Services_Twilio($sid, $token, "2010-04-01"); $call = $client->account->calls->create( $from_number, $to_number, 'http://twimlets.com/message?Message='.urlencode($message) ); echo "Call status: ".$call->status."<br />"; echo "URI resource: ".$call->uri."<br />"; ?> </body> </html>
In addition to making the call, makecall.php displays some call metadata (example shown in screenshot below). For more information about call metadata, see https://www.twilio.com/docs/api/rest/call#instance-properties.
The next step is to deploy your application to Azure Websites. The following articles contain the information for creating a website and deploying your code with Git, FTP, or WebMatrix (though not all information in each article is relevant):
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:
<Say>verb that results in text being spoken to the call recipient. Instead of using the Twilio-provided URL, you could build your own service to respond to Twilio's request; for more information, see How to Use Twilio for Voice and SMS Capabilities in PHP. More information about TwiML can be found at http://www.twilio.com/docs/api/twiml, and more information about
<Say>and other Twilio verbs can be found at http://www.twilio.com/docs/api/twiml/say.
For additional information about Twilio, see https://www.twilio.com/docs.