Twilio SMS Quickstart

Let's walk through creating your first SMS application: Mobile Monkey.

Prerequisites

  1. You'll need a Twilio US local phone number for receiving messages. You can use a free Twilio trial account or signup and get your own dedicated phone number.

  2. You will also need a web host that lets you host web applications. There are lots web hosting services that will host your application for free or for a few dollars a month.

Code

You can download the (minimal) code used in this example if you want:

Hello Monkey, SMS Edition

  1. Let's say your web server answers HTTP requests at companyfoo.com. Create a file called sms-hello-monkey.php in the document root. The URL http://companyfoo.com/sms-hello-monkey.php will be the SMS URL for your phone number.

  2. If you are using a Free Trial Twilio account, browse to your account page on the Twilio website. Scroll down to the "Your Trial Sandbox" and paste the URL of your hello-monkey file (e.g. http://companyfoo.com/sms-hello-monkey.php) in the "SMS URL" box. Hit save and your sandbox account will now now forward SMS messages to your new hello monkey code.

  3. If you are using a Upgraded Twilio account, browse over to the phone number configuration page in your account on the Twilio website. Click on the phone number you wish to use for the demo. If you don't have a phone number, you can purchase one using the "Buy a Number" button at the top of the page. Click the "Edit" link next to the phone number you would like to use. Next, check the "SMS" box, and paste the URL of the PHP file (e.g. http://companyfoo.com/sms-hello-monkey.php) in the "URL" box. Hit save and this phone number will now be setup to receive SMS messages.

  4. Copy the following code into the sms-hello-monkey.php file on your web server. The XML instructions tell Twilio to reply with an SMS that says "Hello, Mobile Monkey" whenever Twilio receives an SMS for your phone number.

    • quickstart/sms/sms-hello-monkey.php
      <?php
      	header("content-type: text/xml");
      	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
      ?>
      <Response>
      	<Sms>Hello, Mobile Monkey</Sms>
      </Response>
          
  5. To test it, send an SMS message to your application's phone number. If you are using the Free Trial sandbox, remember to add your sandbox pin to the beginning of the message. Twilio will receive the SMS, make a request to your URL, http://companyfoo.com/sms-hello-monkey.php in our case, and your server will respond with instructions to send a reply SMS message with the body "Hello, Mobile Monkey".

Hello Monkey Phone Message


Next: Replying to Messages