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.
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…
<?php // include the twilio php help library require "Services/Twilio.php"; // Setup your credentials $account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; $auth_token = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"; // 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 $client->account->sms_messages->create( // who is the sms coming from $from_number, // the number that is receiving the sms $to_number, // the sms body $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.