Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6961391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:31:28+00:00 2026-05-27T15:31:28+00:00

I am using Twilio API to receive SMS text messages. I want to store

  • 0

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 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:31:29+00:00Added an answer on May 27, 2026 at 3:31 pm

    PHP won’t store the information about the text message anywhere, so you are going to lose it. What you describe means that your PHP file will be loaded two times. The first time, the Twilio server will load your PHP file and read the Evil <Response>.

    The second time, you will load the PHP file in your web browser. The $_POST variable depends on information in your browser (and in the Twilio request), so it won’t be the same for both cases. That means you need to save the data somewhere, so it doesn’t get lost. You can use a database, or write it to a text file, when Twilio makes the request and then load the data from the file or the database later. This also helps in case you receive more than one incoming text message – you can store all of them in the file or in the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I include a url in an outgoing text message using twilio API?
I'm using the Twilio API to send broadcast SMS messages based on an approved
I'm using a phone API called Twilio and it does text to voice. I'm
Using WPF/PRISM I want to log my messages through ILoggerFacade to my GUI (A
I have a rails application that I am implementing the Twilio SMS API on,
How can I send an SMS message programatically from an iPhone app? I'm using
I'm trying to get started with Twilio's REST API using the rubygem twilio-ruby ,
I send SMS alerts to my mobile phone using Twilio; I would like to
I am storing sms received from twilio in a database so I can use
Using a script how do I create a text file that contains all of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.