Send Text Notifications using PHP

These are the PHP functions I use to send Text Notifications through messagings.sprintpcs.com from a PHP script.


function http($host, $write)
{
$response = '';
$fp = fsockopen($host, 80);
if ($fp)
{
fwrite($fp, $write);
while (! feof($fp))
{
$response .= fgets($fp, 1024);
}
fclose($fp);
}
return($response);
}

function http_post($host, $page, $post)
{
$write = "POST $page HTTP/1.1\r\n" .
"User-Agent: unknown\r\n" .
"Connection: Close\r\n" .
"Host: $host\r\n" .
"Content-Length: " . strlen($post) . "\r\n" .
"Content-Type: application/x-www-form-urlencoded\r\n" .
"Cookie: \$Version=\"1\"; JSESSIONID=\"none\"\r\n" .
"\r\n" .
$post . "\r\n\r\n";

return(http($host, $write));
}

function sendnote($to, $message = '.', $from = '')
{
GLOBAL $track;

$host = 'messagings.sprintpcs.com';
$page = '/textmessaging/composeconfirm';
$post = "phoneNumber=".$to."&message=" . urlencode($message) .
"&callBackNumber=".$from;

$response = http_post($host, $page, $post);

ereg("\?trackNumber=([0-9A-Z]+)", $response, $regs);
$track = $regs[1];

if (stristr($response, "Message sent")) return 0;
if (stristr($response, "not subscribe")) return 2;
if (stristr($response, "Error")) return 3;
return 4;
}

// Example
$result_code = sendnote("8005551111", "Hi there!", "8005552222");

Note that the tracking number ends up in a global variable called $track.

NqYljRGupanKhfUdp

imavJQUfXMEKsgrPhI

blerRtqpDXdegQp

MJxeNsAEgeLXeVUlnK

prednisone pxxnni valium 20506 tramadol 0499

WxiOybenLyEUItq

SzTNMGZYNDemTqwzGl

dtzVCflGcJkFikA

qTlLKdzNlchZTIk

hAavL6 cosqaycieesm, [url=http://csxvivhietqt.com/]csxvivhietqt[/url], [link=http://jjdvaqzggszm.com/]jjdvaqzggszm[/link], http://mcxrylxhwnbt.com/

Tracking Number Invalid

Do you have any problem with the tracking number being invalid? When I use the script the tracking number always show invalid.

Just wondering...

Re: Tracking Number Invalid

> Do you have any problem with the tracking number
> being invalid? When I use the script the tracking
> number always show invalid.

No, I get valid tracking numbers. When you go to Sprint's website to check a tracking number make sure you do not include any extra spaces (like at the end). Sprint's (rather lame) website will not accept anything other than exactly the 14 character tracking number.

send messages with php

what else do you have to do to get this thing to work. I copied and pasted the code that was posted then uploaded it to my web server. is there anything else i have to do to make it work.

Re: send messages with php

> what else do you have to do to get this thing
> to work. I copied and pasted the code that was
> posted then uploaded it to my web server. is
> there anything else i have to do to make it work.

No, not really. If you simply put PHP tags around it, put it into a .php file and run it on a server, then it will send the message "Hi there!" to phone number 8005551111 from phone number 8005552222.

It doesn't actually display any results. You could add a line like this to the end.
echo $result_code

Send Text Notifications using PHP

How do you get it to work with a form that has an input for the cell number and message?

Send Text Notifications using PHP

First you need an HTML form with fields for the cell number and the message. The form should be designed to submit the results to a PHP script. Then you need to write a PHP script that processes the form by extracting the cell number and message from the HTTP headers. Once you have all that you can call the sendnote() function with the cell number and message from the form.

You might want to look for some PHP examples of HTML form processing. Here's the first hit I found on Google:

http://www.tizag.com/phpT/examples/formex.php/

Send Text Notifications using PHP

can i use your site @ apgap.com to send links to users on my site...if not are you willing to provide me with the complete php codes to send links to my users?

Send Text Notifications using PHP

As long as I have the bandwidth, I don't mind. That's why I set it up. Let me see if I can pull together a simple form to send messages.

By the way, in the Download section, under Power Users, you will find an HTML form for submitting messages to Sprint. It's still not exactly what you are looking at, but it's close.

I'll pull the code from ApGap and see if I can post a more complete example.

Send Text Notifications using PHP

[code:1:6b0610e67c]<?php

function http($host, $write)
{
$response = '';
$fp = fsockopen($host, 80);
if ($fp)
{
fwrite($fp, $write);
while (! feof($fp))
{
$response .= fgets($fp, 1024);
}
fclose($fp);
}
return($response);
}

function http_post($host, $page, $post)
{
$write = "POST $page HTTP/1.1\r\n" .
"User-Agent: unknown\r\n" .
"Connection: Close\r\n" .
"Host: $host\r\n" .
"Content-Length: " . strlen($post) . "\r\n" .
"Content-Type: application/x-www-form-urlencoded\r\n" .
"Cookie: \$Version=\"1\"; JSESSIONID=\"none\"\r\n" .
"\r\n" .
$post . "\r\n\r\n";

return(http($host, $write));
}

function sendnote($to, $message = '.', $from = '')
{
$host = 'messagings.sprintpcs.com';
$page = '/textmessaging/composeconfirm';
$post = "phoneNumber=".$to."&message=" . urlencode($message) .
"&callBackNumber=".$from;

$response = http_post($host, $page, $post);
if (stristr($response, "Message sent")) return 0;
if (stristr($response, "not subscribe")) return 2;
if (stristr($response, "Error")) return 3;
return 4;
}

if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$message = strip_tags($HTTP_POST_VARS['message']);
$callBackNumber = strip_tags($HTTP_POST_VARS['callBackNumber']);
$phoneNumber = strip_tags($HTTP_POST_VARS['phoneNumber']);

if ($err = sendnote($phoneNumber, $message, $callBackNumber))
{
echo "There was an error ($err) sending the message. ";
echo "It probably failed. ";
}
else
{
echo "Message sent successfully. \n";
}
}
else
{
?>
<body>
<form name="composeForm" method="POST" action="<? echo($_SERVER['PHP_SELF']); ?>">
<table cellpadding=4 cellspacing=0 border=0>
<tr><td>Number: </td><td><input title="Number" type="text" name="phoneNumber" size="10" value=""></td></tr>
<tr><td>Callback: </td><td><input title="Callback" type="text" name="callBackNumber" size="10" value=""></td></tr>
<tr><td></td><td><textarea wrap=soft wrap=soft title="Message" name="message" rows="6" cols="30"></textarea></td></tr>
<tr><td colspan=2 align=right><input type="submit" value="Send"></td></tr>
</table>
</form>
</body>
</html>
<?
}
?>[/code:1:6b0610e67c]
That's about as simple of an example as I can make. It displays an HTML form with fields for entering a message. When you submit the form, it's sent to Sprint's website.

I didn't actually test this code. I just looked it over. Hopefully there are no bugs in there. Is that closer to what you were looking for?

Send Text Notifications using PHP

Yes thank you so much for your help...It finally worked for me and I'm also able to change it around a little for my needs...

Send Text Notifications using PHP

This is pretty handy code. It contains enough information to allow me to program a C++ application to do the same thing. I'm going to setup a GTK+ Linux application using the socket library and when I'm finished I will post a link so that you can add it to this site. Hopefully it won't take too long...

Send Text Notifications using PHP

The name of the cookie is now JSESSIONID_JFS.

tCsBjCyawgkGwEB

NDWDdSZIcDwRGJS

TVErmBdaScA

rKIjcRToZx

xJjQsmnlDWFpezSO

IvLIRCgPYjJT

iFSXjOCteeVfvmcB

rEJUvhHEBApEVs

xTFnfSBBvYOM

hVFlvmdemqYUEEQY

wUrtBdDncepRQdnZYs

QgzdnIqTGuQkDiMnN

ZakNazQOlYWWw

xrHWTIvGjUujiWWg

QLKitMoKoqNJUV

tramadol gqil Prednisone yabakp phentermine 3894 Phentermine bgtbut

rVrmsOxtUGyvspu

kHrIXzutvgDABur

WFEzVIDulKDTebcBk

FjSabsXVxhGA