Now we're going to walk you through creating a simple PHP Web Application which can receive and reply to SMS and MMS text messages. Mobile Monkey - your application - will quickly sweep the nation... but first we'll have to handle those incoming texts.
Let's walk through creating your first SMS application.
To get Webhooks working, you will need to find a way to expose your server to the public Internet.
You could host with a web provider, or try one of these tutorials that may be able to help you:
* [ngrok](https://ngrok.com/) * [Deploying PHP to Heroku](http://net.tutsplus.com/tutorials/php/quick-tip-deploy-php-to-heroku-in-seconds/) * [Deploying a PHP App on Google App Engine](https://developers.google.com/appengine/docs/php/gettingstarted/introduction) * [Deploying a PHP app on Dotcloud](http://docs.dotcloud.com/services/php/)
If you're looking to get started quickly, try ngrok. You can read more about ngrok on our blog.
If you choose ngrok, your site will be exposed at
Let's say your web server answers HTTP requests at monkey.ngrok.io.
https://monkey.ngrok.io/sms-hello-monkey.phpwould then be your callback URL.
https://monkey.ngrok.io/sms-hello-monkey.php) in the "A Message Comes In" box. 1. Save the settings, and this phone number will now be setup to receive SMS messages... once you upload your code.
With the infrastructure plugged in, let's work on the code.
sms-hello-monkey.phpfile 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.
<?php header("content-type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; ?> <Response> <Message>Hello, Mobile Monkey</Message> </Response>
php -S localhost:8000
ngrok http 8000
Twilio will receive the SMS, make a request to your URL, https://monkey.ngrok.io/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".
You should receive a text message in response saying, "Hello, Mobile Monkey", but this time an image will be included!
<Response> <Message> <Body>Hello, Mobile Monkey</Body> <Media>https://demo.twilio.com/owl.png</Media> </Message> </Response>
Note: you can even send multiple images by adding more
<Media> elements to your response. Check out the official docs for more details.
And with that, you can receive and reply to SMS and MMS text messages in PHP. Not bad, now sweep the world with your application!