Reputation: 3828
Using Twilio and a php script how do I get the from number and body data from an incoming sms?
I have a paid account. My incoming texts are being sent to my php script via twilio but I just need to know how to get the number and body.
This should be easy but its not.
<? // my script
$from = ???;
$body = ???;
?>
Please provide a php example if you can because I don't understand their api with no examples. Thanks
Upvotes: 1
Views: 1263
Reputation:
The biggest problem with all of the Twilio documentation is it assumes you have experience of RESTful services, I have had numerous issues with this myself purely for the same reason. I have found this helpful because it explains in a few lines of code where to get and how to deal with the information. WHICH if you search for this it is VERY hard to find. Everywhere there are examples of send SMS and none for Receive. Hope that helps. p.s. Im banned from asking questions here because I don't know enough!!! I have no idea how this works but everyone has to start somewhere as this post shows perfectly.
<?php
$number = $_POST['From'];
$body = $_POST['Body'];
header ('Content-Type: text/xml');
?>
<Response>
<Message>
Hello <?php echo $number ?>.
You said <?php echo $body ?>
</Message>
</Response>
Upvotes: 0
Reputation: 10366
Twilio evangelist here.
Parameters are passed from Twilio as form-encoded data, so you can use PHP's $_REQUEST
object:
$_REQUEST['From']
Check out this Quickstart for a longer example:
https://www.twilio.com/docs/quickstart/php/sms/replying-to-sms-messages
Hope that helps.
Upvotes: 1