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

  • Home
  • SEARCH
  • 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 7586237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:22:40+00:00 2026-05-30T19:22:40+00:00

I’m using the Twilio API to send broadcast SMS messages based on an approved

  • 0

I’m using the Twilio API to send broadcast SMS messages based on an approved number. The problem in which I have encountered is not being able to successfully run a query pulling the phone information from a database and enter it into the API for each results that meet the query criteria to send an SMS to. The below is what I have so far.

    //Include the PHP TwilioRest library
    require "Services/Twilio.php";

    //Set our AccountSid and AuthToken
    $AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXX";

    $AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYY";

   //Instantiate a new Twilio Rest Client
    $client = new Services_Twilio($AccountSid, $AuthToken);

//Trusted numbers that we want to be able to send a broadcast

    $trusted = array("+33333333333" => "ApprovedAdmin1");

//An unauthorized user tried to send a broadcast.

    if(!$name = $trusted[$_REQUEST['From']])

    {header("content-type: text/xml");echo "\n";echo "Unauthorized broadcaster, contact an admin for access.";exit(0);}

//These are the recipients that are going to receive the broadcasts

//database user credentials  
    `$user = "user";`  
    `$password = "password";`  
    `$database = "database";` 
    `$host = "localhost";`  
//connect to the database  
    `$DB = mysql_connect($host, $user, $password) or die("Can't connect to database.");`  
    `@mysql_select_db($database) or die("Unable to select database");`

//Used to query database for only user phone numbers who accept texts

    $recipients = array (mysql_query("SELECT phone FROM sms WHERE (accept_text = 'Y')"));

//I have commented this out to try to get the query to work. The below recipients array does work and even lists the names of the user in the SMS.

    //$recipients = array("+22222222222" => "testuser1");

//Grab the message from the incoming SMS

    $msg = $_REQUEST['Body'];

// Iterate over all our recipients and send them the broadcast

    //foreach ($recipients as $number => $name) {

//Send a new outgoinging SMS by POSTing to the SMS resource

    $sms = $client->account->sms_messages->create("3333333333",$number,"$name, " . $msg);echo $name . " ";}
  • 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-30T19:22:41+00:00Added an answer on May 30, 2026 at 7:22 pm

    Ok so first of all you are not executing valid XML on the error condition e.g. if the user is not a trusted number. If you want to reply to the texter that the number is unauthorised you would need to do:

    header("content-type:text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    echo "<Response>\n<Sms>Unauthorized broadcaster, contact an admin for access.</Sms>\n</Response";
    

    I’m not sure what you are trying to do with the query – why is it in an array? And I don’t know why you then have a recipients array – surely this is what you are pulling in from the database? You need to do:

    $result = mysql_query("SELECT phone FROM sms WHERE accept_text = 'Y'");
    while($row = mysql_fetch_assoc($result)) {
        $client->account->sms_message->create("3333333333", $row['phone'], $_REQUEST['Body']); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.