Script to Load a list of #'s To Send a Msg To


I was busy all day. I see you made some headway while gone. If the text file of numbers is given to you and is simply a list of numbers, you could just read the file itself. There is PHP code to do that. But, to create a PHP script for you to do this, we need some small questions answered.

First, do you have a server to place the program on or do you run it on your computer using Mamp or Wamp?
Next, is the text file just one list of numbers like in the original post? I mean, just a list of numbers?

It is very easy to read the text file. And, then pull out the numbers. Just need to know the exact format of the text file itself. It is extremely easy to create the link with the numbers in place. You would just need to put in some timing so that you did not post to the other site too fast. This would probably be best to use Curl so that you can get some error checking. Sending out 2000 at a time is not a big issue. But, you would need to delay between each so it does not cause issues at the other end.

Another way would be to read the numbers into a check-list and you could select the ones you wanted to send out to using the submit button. It would be simple, but, would work.

Another question. Would you send out just one SMS per number or would you repeat them often?


First: Yes we have a server running PHP v I believe as it is installed with vici dial and he’s scripts to operate the dialer are written in PHP.

Second: The file is either a txt or CSV file in which yes only has one column of phone numbers 10 digits long, no country code.

so yes it would work great if we could either copy and paste or load a file in which it just put in number after number with the same exact information I previously posted.

And last; only one SMS per phone number per day at most.


Great! Okay, I can drum something up for you…

If you plan to just send them, the script can just read the text file and send them out. Should not be a problem.


Here is an example of one code that would work. But, it does need some adjusting.
First, you need to put in the name of the text file that contains the numbers. I used numbers_file.txt for example.
Next, if you are sending all 2000, you might need to lower the sleeping time between each execution.
I set it at 1 second, but, think that .5 or .3 might be enough time. 2000 numbers times 1 second would be 30 minutes and that is a long time for a script to run. You might try .1 and see how 1/10th of a second does for you.

ALSO, you might want to test it with a text file that has your own phone number in the list, three times.
That way, you should get 3 text’s one after the other and can test it that way to make sure it is working.

I could not test this as I do not currently have a working cell phone. It does not have much in the way of error-checking. Press the button and it sends the message to all the numbers in the text file. You must make sure the text file is set up with one phone number per line. It does check if the URL is posted and displays a note if it worked or failed. You might want to remove the worked display so it only shows failed ones.

This should at least get you started… I am leaving for several hours, but, ask questions if any…

if (isset($_POST["submit"])) {
    $numbers_file = fopen("inputfile.txt", "r");

    //  Read one line at a time ( one phone number per line )
    while (($phone_number = fgets($numbers_file)) !== false) {
        //  Process the one phone number, create the URL paramenters with info in the correct places
        $url_parms = "?token=e9cf7e33-0c00-4eb5-94fb-7ae060fa4329&source=8445972807&destination=" . trim($phone_number) . "&message=This is The National Health Enrollment Center. You are still eligible to enroll in an affordable health insurance plan. Call 844-597-2807 now to speak with a licensed agent.";

        //  Using the created URL, send it using Curl
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,"");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $url_parms);

        // Receive server response ...
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $server_output = curl_exec($ch);

        //  Close Curl 
        curl_close ($ch);

        if ($server_output == "OK") {
            echo "SMS sent out to: " . $trim($phone_number) . "<br>";
        } else {
            echo "ERROR sending SMS to: " . $trim($phone_number) . "<br>";

        //  To not cause issues with the server being overwhelmed, delay one second between SMS' .   This might be able to be lowered.

    //  Close the file
 <!DOCTYPE html>

<h1>Send SMS messages to all numbers in text file</h1>
<input type="submit" name="submit" value="send_now" />



I have attempted testing and have not yet had success. The site is limiting me for number of replies so I couldn’t tell you this right away. The $numbers_file… Does the filename have to be the same as that? Because I named it “textfile.txt” and did change the one name there as well as put it in the same directory. I have tried everything I know but to no avail. And it is at

    $numbers_file = fopen("inputfile.txt", "r");

As it says, you need to change the name of the file from “inputfile.txt” to your name of the file.
ALSO, the file must be in the folder where this program is. So, you have to load the text file and this file into
the same folder… So, if the file is textfile.txt, then the code would be:

    $numbers_file = fopen("textfile.txt", "r");

Note the open part…

Does that help?


Yes I have done that. When I press submit nothing happens. I have made sure all directories and files have the correct permissions, altered/tested different areas of code to elicit some type of response, file is in the same folder and if anyone wants to see this for themselves I am willing to grant access to the server via WinSCP to verify or alter anything they see fit to make this operational. Please help and MUCH THANKS AND LOVE to the help already received: I wouldn’t have been able to make it this far without it


Look for an error log


Where would I find an error log at?


Do you know the OS the server is using?

if (isset($_POST["submit"])) {

Change the top of the code to this:

ini_set("display_errors", 1);
if (isset($_POST["submit"])) {

This turns on errors for displaying and that way they might show up on your page. Some times will not.
If it is a Curl error, you can display them, but, I added some code in it for that.
Are you getting ANY displays when you run this?


astoncipher: It is a server that was loaded from a Vicibox ISO 8.1.2, so the OS should be OpenSUSE 13.1. The system is a webserver/dialing platform with all the trimmings it needs to run this script no problem.

ErnieAlex: Absolutely no output whatsoever. Try it for yourself at

Also if you need access to the server I am willing to grant you root for a small period of time for you to troubleshoot with me if possible. My phone number is 813-481-3879… Yesterday the site only let me reply so many times before I had to wait 5 hours to reply and that really cut down on my productivity lol


And further down,



813? Isn’t that Tampa?

OpenSUSE is based on BSD, correct?
Try looking here: /var/log/


I have done all instructions, still no errors displayed unless I make an error in entering code and try to reload the page - Then it does go to the /var/log folder.

Still no output at all when send_now is pressed. Not sure what’s going on, but it doesn’t even appear to be running the script to send a text at all. Any other info or help? Below I will post the scriptsThird Rock Telecom gives for Send/Receive SMS



The ability to send and receive SMS and MMS messages. Your DID to a cell phone and vice versa. All just a web call away.


SMS is intended for enhancing person to person communication. You may not send more than 1 message per second per phone number and no more than 3,000 messages per day per number. You are also not to spam the same message to multiple people.

Sending spam or many automated messages will result in immediate SMS suspension.

Controller: /sms or /mms
Full Url: NOTE: The URL here is different than a lot of the rest of the API

  • Content-Type: application/x-www-form-urlencoded
  • Encoding: UTF-8


  • /sms/send
  • /mms/send


Full Url:


  • token (string, required)
  • source (int, required)
  • destination (int, required)
  • message (string, required)

Info: source must be a number from your inventory. Basically, you’re saying “Send an SMS from this number to that (10 digit) number. Here’s the message”.


Full Url:


  • token (string, required)
  • source (int, required)
  • destination (int, required)
  • file_name (string, required conditionally)
  • file_data (base64 encoded file data, required conditionally)
  • file_url (url encoded url, required conditionally)

Info: source must be a number from your inventory. file_data needs to be a base 64 encoded string of your file’s contents. Alternatively, if you already have a URL for the image you can simply send us that url in file_url . We’ll grab it and do the rest for you. Ultimately, though, we need file_name and file_data OR file_url. Your choice.

Example PHP MMS message

Update: There is also a PHP client library available at

$source = "3035551212";
$destination = "3039991111";
$token = "32hfrehfehrfh34f";
$file_name = "catpicture.png"; //you know someone's going to do it..
$file_data = file_get_contents('/path/to/file/' . $file_name);
$file_data = base64_encode($file_data);

$baseurl = "";
$data = array(
    'token' => $token,
    'source' => $source,
    'destination' => $destination,
    'file_name' => $file_name,
    'file_data' => $file_data
$data = http_build_query($data);

$ch = curl_init($baseurl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/x-www-form-urlencoded',
    'Content-Length: ' . strlen($data)
$response = curl_exec($ch);
$response = json_decode($response);
if ($response->code == 200) {
} else {

Receiving SMS/MMS

In order to receive SMS or MMS messages we need somewhere to send them. In your “My Settings” page in the user portal, there is a settings for “Incoming SMS Post URL”. All messages that come to any of your phone numbers will get sent to this URL via HTTP POST. So, all you need is a script that will consume these web calls and do something with it.

message=Hello, World!

message=[unique identifier]
PHP example

Update: There is also a PHP client library available at

$source = $_POST['source'];
$destination = $_POST['destination'];
$message = $_POST['message'];

//save to a csv file... if you're into that sort of thing
$csv_line = sprintf('%s,%s,%s', $source, $destination, $message);
file_put_contents('/path/to/awful_csv_log.csv', $csv_line);

//make it show up in apache's error log
error_log(print_r($_POST, true));

//I've gone to Cancun and "acccidentally" left my phone at home
$ch = curl_init('');
$data = array(
    'token' => $my_api_token,
    'source' => $destination,
    'destination' => $source,
    'message' => 'Hello. I am unavailable right now. Please leave a brief message and I will get back to you when I'm sober.'
$data = http_build_query($data);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/x-www-form-urlencoded',
    'Content-Length: ' . strlen($data)
$resp = curl_exec($ch);
$resp = json_decode($resp);
if ($resp->code == 200) {
    //the boss is mad
} else {
    //the boss is still mad. but he didn't get a snarky message

Delivery Notifications

Delivery Notifications are only supported via our API and SMPP connections. We don’t support delivery notifications via Jabber/XMPP or Slack.

Let me preface this by saying delivery notifications are not always a sure thing. In order for delivery notifications to work every hop along the way, from here to the end number, has to send them. Sometimes they don’t. Also, sometimes you won’t get a delivery notification for quite a while. It all depends on many variables from here to there. That said, they can be very nice in letting you know how successful your SMS message was. They are also asynchronous. This means that sending the message is a separate process from knowing if the message is delivered or not, which is why this is a separate web call to look for.

Breakdown of the delivery notification process:

  1. You give us a message to send to some end number
  2. The API call that you made to us to send the SMS message ends, in the response is an ID that we will refer to when we deliver the notification
  3. We pass that message along to carriers
  4. Carriers may pass to other carriers
  5. Message gets delivered to device, or is rejected, fails, etc
  6. A notification is passed back down the chain of carriers, one by one, with the status of the message
  7. The notification finally makes it back to us
  8. We grab your SMS Delivery Notification URL and, finally, pass that notification on to you via HTTP POST using the ID we gave you as a reference point

To receive delivery notifications via HTTP POST, simply set an SMS Delivery Notification URL in your My Accounts page in the user portal. Once set, you will receive notifications for all messages sent.
To receive delivery notifications via SMPP, send a registered_delivery value of 1 in your submit_sm command to send the message.

The POST that you get to your server will look something like:

  url: '',
  id: '72b83667-a8f1-4c09-861f-e1ee6dd4561b',
  send_status: 'delivered',
  status: 'DELIVRD',
  error: '000'

Possible send_status:

  • delivered
  • carrier-reject
  • failed

Possible error code / status:

  • 000 or (less likely) 002 / DELIVRD
  • 003 / EXPIRED
  • 004 / DELETED
  • 005 / UNDELIV
  • 007 / UNKNOWN
  • 008 / REJECTD

Since all DLR information is relayed from upstream providers and differences in carrier specific response types exist in an unregulated industry, error codes will by varied. Instead of using this information, we suggest looking at the status to determine the cause of an error or send_status for high level checking.


To debug it, you can add this in to display each number it is processing.

// Read one line at a time ( one phone number per line )
 while (($phone_number = fgets($numbers_file)) !== false) {
     echo "Processing number: " . $phone_number . "<br>";

And, this should show the number it is using for each step. If you do not get any, then the text file is not being opened correctly or is not formatted as a text file with each number on a separate line.
Debugging is a step by step process.

As I was writing this, you posted. I see you already have the send Curl code. All you would need to do then is to add in the file reading code and set your tokens up in that code and it should work. Do you understand how to do this?


You need to add logging as well. That way you can see what the return message is when you send the request…

I can take a look in a bit, but I am waiting on a response from business for a hotfix they want to go out.


After following the steps to have it echo each phone number it’s processing and clicking “send_sms” I still got absolutely no response. The page just stays exactly as it is so I guess it isn’t properly processing the file as you said. The line I have for opening the file reads exactly as is:

$numbers_file = fopen("textfile.txt", "r");

So with that, all I did to make the file is I just typed my number 3 times into notepad like this:


and saved it as a .txt file. The encoding at the bottom says it’s ANSI… Should it be unicode or UTF-8? Did you see anything else I can do to debug?


Did you save the file you created with the name “textfile.txt” and save it on the server in the same folder as the codepage is stored?

I don’t think the encoding matters. I have used notepad to create files before.


I put them both in their own folder, both files in the same folder. The file for the webpage is called “smstext.php” and the text file is called “textfile.txt”. Once again they are in their OWN folder together and the folder is named “text”.