Skip to content

Instantly share code, notes, and snippets.

@rahims
Created July 22, 2011 20:55
Show Gist options
  • Save rahims/1100405 to your computer and use it in GitHub Desktop.
Save rahims/1100405 to your computer and use it in GitHub Desktop.
Sample code on how to take an SMS and respond with an SMS based on what the person sent in
<?php
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<Response>
<?php
// When an SMS comes into your Twilio phone number, Twilio passes
// the body of the SMS to your web app in the Body parameter.
$keyword = strtolower(trim($_REQUEST['Body']));
switch ($keyword)
{
case 'hi':
$reply = 'Hello there!';
break;
case 'are you a human?':
$reply = 'Of course I am!';
break;
case 'oh yeah? prove it!':
$reply = 'Uh...how would I do that?';
break;
// And so on
default:
$reply = 'Sorry what was that?';
}
echo "<Sms>$reply</Sms>";
?>
</Response>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment