开发者

Sending SMS through Twilio using PHP

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.


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


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜