Reputation: 31
Hi Twilio and PHP dev,
I am newbie to PHP. Can anyone show me a simple sample code of php that accepts sms from twilio.
I mean I need a simple phph code that I can include in my site which accepts a sms message from twilio.
I need one way communication only as of now!
Plz, somebody give a example with few lines of code. I am struggling with php from long back.
Thanks, Kris.
Upvotes: 3
Views: 4391
Reputation: 657
The SMS Quickstart Guide provides averthing you need. Here's a direct copy+paste of my incoming text script. It does some extra stuff (like logging the message into a database for tracking conversations, etc.), so you really only need the header()
part and echo
part, with the TwiML below it.
<?php
require "sms.init.php";
$db = new Handler();
$sid = $_REQUEST['SmsSid'];
$acct_id = $_REQUEST['AccountSid'];
$from = substr($_REQUEST['From'], 2);
$to = substr($_REQUEST['To'], 2);
$body = $_REQUEST['Body'];
$thread = md5($from + $to);
$db->recordSMS($acct_id, $from, $to, $body, "inbound", $thread);
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Sms>Text Logged into Database.</Sms>
</Response>
Upvotes: 2
Reputation: 1552
Twilio has some sample code on how to send SMS messages through their API:
http://www.twilio.com/docs/howto/sms-notifications-and-alerts
http://www.twilio.com/resources/tarball/sms-notification.zip
Upvotes: 5