I am using Twilio API to receive SMS text messages. I want to store the number and the body of the received message. It is being received in an xml php page, I want to use it in a middle of a different php page. How should I go about it? The message is being received via a Post request, twilio updates the xml php file once it is received.
This is the xml php file code:
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Sms>Hello again, Dr. Evil</Sms>
</Response>
<?php
$body = $_POST['Body'];
$responder = $_POST['From'];
if ($body) {
// if some response has been received, tell us what it is
// echo "<Body>".$body."</Body>"; <--wrong
// echo "<Responder>".$responder."</Responder>"; <--wrong
};
?>
The "if" statement in the last few lines doesn't seem to be working. Should I be using javascript(&jquery) instead? how? I'm a novice, so be kind...
Thanks!
Update1:
I tried saving to database as you suggested, and it still isn't working... :(
Here's the new code:
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Sms>Hows it going, Dr. Evil</Sms>
</Response>
<?php
$body = $_POST['Body'];
$responder = $_POST['From'];
if ($body) {
require_once "../includes/functions.php";
connectDatabase();
//storing message and sender in database
mysql_query("INSERT INTO sms_received (responder, body)
VALUES ('$responder', '$body')");
mysql_close();
};
?>
Update2:
Okay, I debugged it, this last time I had a problem with the path, but this code is working now!!!
Thank you all :-)