Send SMS with PHP and Twilio

PHP and sending SMS with Twilio

It takes just a few lines of code and even fewer minutes to send your first text message with PHP and Twilio. Here’s how:


Sign up for a free Twilio account and buy a phone number.

Install the PHP helper library with Composer: composer require twilio/sdk:5.* then put   require "vendor/autoload.php'; at the top of your file.

Find your account SID and auth token in your console dashboard, and your phone number in your phone numbers list.

Create a file called send-sms.php  and paste in the code below to:

  1. Include the helper library
  2. Create a Twilio client using our account credentials
  3. Create a new message from our Twilio number, to our cellphone

Save your file and run it:

Boom! Your phone should light up with a text!

Next Steps

We’re just scratching the surface of what’s possible with PHP and Twilio. If you’d like to explore more, check these out:

If you build something sweet using PHP and Twilio, or if you have any questions, I’d love to hear about it. Please drop me a line at @greggyb or



  • Brandon Leon

    Where should I start my troubleshooting if I’m getting PHP Fatal error: Class ‘Services_Twilio’ not found? twilio/sdk 5.2.0 is installed via composer and the first line is require “vendor/autoload.php”; (Also in your example you started the require statement with a double quote and end it with a single quote).