Menu

Expand
Rate this page:

Make Outbound Phone Calls with PHP

In this guide, we'll show you how to use Programmable Voice to make outbound phone calls from your PHP applications. It's pretty easy - all you'll need is the Twilio library for PHP , a voice-capable Twilio phone number, your account credentials, and five minutes to have a boatload of fun at your keyboard. Let's get started!

Purchase a voice-enabled Twilio phone number

In the Twilio console, search for and purchase an available phone number capable of making outbound calls. You'll use this phone number as the "From" phone number when you initiate an outbound call.

Search for voice capable numbers

Retrieve your Twilio account credentials

First, you'll need to get your Twilio account credentials. They consist of your AccountSid and your Auth Token. They can be found on the home page of the console.

Retrieve Your Twilio Credentials

Make an outbound call

Now we're ready to make an outbound call with the Twilio PHP library.

        
        
        
        

        There are a few key parameters to drill into when making the outbound call.

        • "From" - the voice-enabled Twilio phone number you added to your account earlier
        • "To" - the person you'd like to call
        • "Twiml" - Instructions in the form TwiML that explains what should happen when the other party picks up the phone
        • "Url" - Optionally, instead of passing the Twiml parameter, you can provide a Url that returns TwiML Voice instructions.

        What is TwiML?

        TwiML is the Twilio Markup Language, which is just to say that it's an XML document with special tags defined by Twilio to help you build your SMS and voice applications. TwiML is easier shown than explained. Here's some TwiML you might use to respond to an incoming phone call:

        <?xml version="1.0" encoding="UTF-8"?>
        <Response>
            <Say>Thanks for calling!</Say>
        </Response>
        

        And here's some TwiML you might use to respond to an incoming SMS message:

        <?xml version="1.0" encoding="UTF-8"?>
        <Response>
            <Message>We got your message, thank you!</Message>
        </Response>
        

        Every TwiML document will have the root <Response> element and within that can contain one or more verbs. Verbs are actions you'd like Twilio to take, such as <Say> a greeting to a caller, or send an SMS <Message> in reply to an incoming message. For a full reference on everything you can do with TwiML, refer to our TwiML API Reference.

              
              
              
              
              This uses the Url parameter

              Make an outbound call with hosted TwiML

              This uses the Url parameter
                    
                    
                    
                    
                    This XML document uses the <Say> and the <Play> TwiML tags to read a message and play an MP3 file for the user.

                    The TwiML used to make the outbound call

                    This XML document uses the <Say> and the <Play> TwiML tags to read a message and play an MP3 file for the user.

                    Of course, the TwiML you use to make the outbound call doesn't need to be a static file like in this example. Server-side code that you control can dynamically render TwiML to use for the outbound call. Check out our inbound call guide to see an example of a PHP snippet which generates TwiML.

                    Where to next?

                    Great work! In a few lines of code, you've placed an outbound phone call from your PHP code. If you're using Programmable Voice with PHP, you might enjoy these other guides as well.

                    Happy hacking!

                    Agustin Camino Maylon Pedroso Jarod Reyes Rob Spectre Ricky Robinett David Prothero Kevin Whinnery Craig Dennis Andrew Baker
                    Rate this page:

                    Need some help?

                    We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

                          
                          
                          

                          Thank you for your feedback!

                          We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

                          Sending your feedback...
                          🎉 Thank you for your feedback!
                          Something went wrong. Please try again.

                          Thanks for your feedback!

                          Refer us and get $10 in 3 simple steps!

                          Step 1

                          Get link

                          Get a free personal referral link here

                          Step 2

                          Give $10

                          Your user signs up and upgrade using link

                          Step 3

                          Get $10

                          1,250 free SMSes
                          OR 1,000 free voice mins
                          OR 12,000 chats
                          OR more