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

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

Send:


Overview

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.

Restrictions

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: https://sms.teleapi.net/sms/ 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

Functions

  • /sms/send
  • /mms/send

/sms/send

Full Url: https://sms.teleapi.net/sms/send

Arguments:

  • 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”.

/mms/send

Full Url: https://sms.teleapi.net/mms/send

Arguments:

  • 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 https://github.com/teleapi/php-client

$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 = "https://sms.teleapi.net/mms/send";
$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);
curl_close($ch);
$response = json_decode($response);
if ($response->code == 200) {
    //success
} else {
    //fail
    print_r($response);
}

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.

Example HTTP POST
//SMS
source=3035551212
destination=3039991111
message=Hello, World!
type=sms

//MMS
source=3035551212
destination=3039991111
message=http://picmsg.org/[unique identifier]
type=mms
PHP example

Update: There is also a PHP client library available at https://github.com/teleapi/php-client

$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('https://sms.teleapi.net/sms/send');
$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);
curl_close($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: 'http://yoursite.com/sms/notifications',
  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:

8134813879
8134813879
8134813879

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”.

create a new file called smstext2.php. Put this code in it and bring it up in a browser.
See if it displays the numbers or not. We need to debug it step by step.

<?php
    //  Open the text file.
    $numbers_file = fopen("textfile.txt", "r");

    //  Read one line at a time ( one phone number per line )
    while (($phone_number = fgets($numbers_file)) !== false) {
           echo $phone_number . "<br>";
   }
    //  Close the file
        fclose($numbers_file);
?>

Yes this did display the phone numbers, all 3 of them

Okay, in that case, we will have to rewrite my code using the version you posted.
I will post it in a bit once I sort it out…

I can’t thank you enough. Once again I hope we can discuss an option where you would be open to consulting for us in the future.

Try this version. I was reading your details and this service does not allow more than one call per second and they do not allow sending the same message to large number of phones. Therefore, you might need to add some sort of reference number inside the message so that the message is different each time. Not sure at all on this…

<?php
if (isset($_POST["submit"])) {
    //  Open the text file.   ( HERE YOU WOULD NEED TO CHANGE THE NAME OF THE FILE TO YOUR FILENAME ! ! ! )
    $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,"https://sms.teleapi.net/sms/send");
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $url_parms);

        // Send message and receive server response ...
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        curl_close($ch);
        $response = json_decode($response);
        if ($response->code == 200) {
            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.
        sleep(1);
    }

    //  Close the file
        fclose($numbers_file);
}
?>
 <!DOCTYPE html>
<html>
<body>

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

</body>
</html>

I changed the error reporting section and also added quotes on your message as I think that might be a problem. Good luck…

It’s still not working. I’m not sure that the “Send Now” button is doing anything… I wonder if we can run this just by taking that button out? Btw it’s not that they it won’t let you send those texts that fast or what have you, it’s that they will stop the account and flag it as spam if you do. We have already spoken with the company and gotten the go ahead though…

Once again, this page has been uploaded to the same folder with all the same options and unfortunately is still not doing anything. No error codes or nothing.

Oh, RATS! It must be inside a form to post. My fault… Change the bottom part to:

<!DOCTYPE html>
<html>
<body>
    <form action="#" method="post"> 
        <h1>Send SMS messages to all numbers in text file</h1>
        <input type="submit" name="submit" value="send_now" />
    </form>
</body>
</html>

VERY VERY sorry about that! Typed the original off the top of my mind and did not test…

Also, you should probably place all of the PHP code inside of the form area after the input so that it displays the output on the live page. So, all the PHP code would be between the <input tag and the </form tag…

have done everything you said and have successfully (with the echo script) received back a “Processing: 8134813879”

And that’s where it all stops LOL. It doesn’t show that it processes any other numbers and also I didn’t receive a text.

Sorry I got delayed again. Perhaps there is an email you could private message me on or can I pay to not be restricted?

You don’t have to pay, we will solve it for free. I have also been extremely busy. We just need to debug the code to see what it is doing wrong. I can test it from here since you have included your token in the post’s.

I will do so later today as I am working right now. I think we are close. Talk to you a little later in my day.

I’m really curious about this. Where are you restricted, because it sounds like you are saying you are restricted to posting in the forum?

Exactly. I can only post so many times before I get restricted. Essentially when I meet the limit I go to type in my reply and when I click reply to send it it explains that I have hit a limit and can post again in six hours

Steve, there is no time limit on posting here. Are you using a regular computer to post here with?
And, what country are you in?

Sponsor our Newsletter | Privacy Policy | Terms of Service