Sending SMS from your PHP application using Twilio

I am constantly hearing that one of the advantages of going with native mobile apps is that you can send push notifications.

So, one thing people keep forgetting is that all mobile phones can receive a certain format of notifications. Yes, ALL mobile phones… Can you tell what it is yet? Mobile phones have this magical messaging system called SMS…

So you want to send an SMS to one of your users from within your PHP app. Perhaps you want to use it to send a notification, or you just want to keep your customer updated.

So, let me just tell you this. It is stupidly easy. So, once you have signed up for a FREE test Twilio account. Download the PHP helper library or from Github.

Then in your application, include the PHP helper library, add your account credentials: your auth token and your Account SID.

Then you are good to go…


    // include the twilio php help library
    require "Services/Twilio.php";

    // Setup your credentials

    // Step 3: instantiate a new Twilio Rest Client
    $client = new Services_Twilio($account_sid, $auth_token);

    // the number that the sms will come from 
    $from_number = "+1234343434";

    // the number that will receive the sms
    $to_number = "+1234343434";

    // this is the sms that will be sent
    $sms_body = "Hey there :) here is an SMS";

    // boom, send the sms message

        // who is the sms coming from

        // the number that is receiving the sms

        // the sms body


BOOM, SMS sent. How stupidly easy was that? Now all your apps can communicate with real phones, and it takes hardly any time at all.

Let’s say you don’t want to use PHP, because you are a cool kid using Node or Ruby. Well Twilio has helper libraries for all kinds of languages, and they are all about as simple as this one!

What kind of things would you use it for? Web app notifications, reminders, authentication, or just simply communications.

If you do make anything interesting with Twilio, or even anything else, make sure you let me know! I love to see the kind of things people are making.

Back to the articles