Error

Notice: Undefined property: stdClass::$forum_tid in forum_node_view() (line 275 of /home/wfrantz/www/sprintdevelopers/modules/forum/forum.module).

Send Text Notifications using PHP

Submitted by wfrantz on Wed, 09/22/2004 - 15:10

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.