Back to Blog
Language How-Tos

How to Make an Outbound Phone Call in Twilio Using PHP

Initiate outbound voice calls from PHP using the Twilio REST API client with TwiML callback URL and call status tracking.

DA
Danial A
Senior Twilio Consultant, Telphi Consulting
June 22, 2026
8 min read
Twilio
PHP
How-To
Code
How to Make an Outbound Phone Call in Twilio Using PHP

This tutorial shows how to initiate an outbound phone call from PHP using the Twilio REST API with a TwiML URL that controls what Twilio says or plays when the call connects. It targets PHP developers adding automated voice notifications, appointment reminders, or call-based alerts to their applications. You will trigger a real outbound call and serve the TwiML instructions from a separate PHP endpoint on the same server.

Prerequisites and Setup

Install the packages with composer require twilio/sdk vlucas/phpdotenv and expose your local PHP server with ngrok using ngrok http 8000. The url parameter in the calls create call must point to a publicly accessible HTTPS endpoint that returns TwiML XML; use the ngrok HTTPS URL followed by your TwiML script path during development. Twilio fetches the TwiML URL as an anonymous HTTP client once the call connects, so the endpoint must not require authentication headers or session cookies. Store your Account SID, Auth Token, and phone number in a .env file loaded by Dotenv.

composer require twilio/sdk vlucas/phpdotenv

# .env
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TWILIO_AUTH_TOKEN=your_auth_token_here
TWILIO_PHONE_NUMBER=+15551234567

The Complete Code

The calls->create() method takes the recipient number as the first argument, the caller ID as the second, and an options array containing the url as the third. The voice.php TwiML endpoint instantiates a VoiceResponse and uses the say() method to build a spoken message using Twilio's Alice voice. The returned call object has a sid property starting with CA that you can store and use to query or cancel the call programmatically. Logging the SID immediately lets you look up call details in the Twilio Console without waiting for the call to complete.

<?php
// make-call.php
require_once 'vendor/autoload.php';

use TwilioRestClient;
use TwilioExceptionsRestException;

$dotenv = DotenvDotenv::createImmutable(__DIR__);
$dotenv->load();

$client = new Client($_ENV['TWILIO_ACCOUNT_SID'], $_ENV['TWILIO_AUTH_TOKEN']);

try {
    $call = $client->calls->create(
        '+15551234567',
        $_ENV['TWILIO_PHONE_NUMBER'],
        ['url' => 'https://xxxx.ngrok.io/voice.php']
    );
    echo 'Call SID: ' . $call->sid . PHP_EOL;
    echo 'Status: '   . $call->status . PHP_EOL;
} catch (RestException $e) {
    echo 'Error ' . $e->getStatusCode() . ': ' . $e->getMessage() . PHP_EOL;
}
<?php
// voice.php - TwiML endpoint
require_once 'vendor/autoload.php';

use TwilioTwiMLVoiceResponse;

$response = new VoiceResponse();
$response->say(
    'Hello. This is an automated message from Telphi Consulting.',
    ['voice' => 'alice']
);

header('Content-Type: text/xml');
echo $response;

Testing and Debugging

Run php make-call.php and verify a call SID starting with CA prints to the terminal while your phone rings. If the phone rings but you hear silence, check that voice.php is returning a 200 with a Content-Type: text/xml header and valid TwiML XML. Error code 13224 in the Twilio Console means Twilio could not fetch your TwiML URL; confirm your ngrok tunnel is still running and the path in the url option matches the filename of your TwiML script. Check the Twilio Console under Monitor for the full call lifecycle and any error codes returned during TwiML execution.

Taking It Further

Add a statusCallback key to the options array pointing to a separate PHP endpoint so Twilio POSTs call lifecycle events such as initiated, ringing, answered, and completed for real-time tracking. Pass 'machineDetection' => 'Enable' in the options to activate answering machine detection so your TwiML can differentiate between a human answer and a voicemail greeting. Use the timeout parameter to control how many seconds Twilio lets the call ring before treating it as unanswered and moving on. Pass personalised data as query parameters in the TwiML URL and read them with $_GET in voice.php to construct a dynamic spoken message per call.

Contact Telphi Consulting to design outbound call campaigns with dynamic TwiML, answering machine detection, and call analytics in PHP.

Share this article:
0 views

Ready to Transform Your Business Communications?

Get a free consultation with our VoIP experts and discover how we can help you save costs, improve efficiency, and scale your business.

Comments (0)

Join the discussion and share your thoughts (AI-moderated for quality)

Protected by AI moderation

Be the first to comment

No comments yet. Share your thoughts below.