Sending mobile text messages from your Instant Messenger

Sending mobile text messages from your Instant Messenger

One of the most useful features of Instant Messaging is the availability of user presence, or the ability to know whether a user is online or not.
Of course, if a user is unavailable and you really want to get a message to them, it would probably be really cool if the message could be sent to their mobile phone.

While many of the latest mobile phones are beginning to support Instant Messaging, nearly all of them support SMS text messaging.

It would be great to send an Instant Message to user’s cell phone, and this Hack show’s how to do that, by using the email to SMS gateway, which most provider’s have available.

Running the Hack
First, you’ll need to have a few Jabber accounts set up and have class.jabber.php downloaded and placed inside your hack directory as shown in Sending IM Alerts Hack.

Next, edit the config variables at the top of the code which hold the values of the formats of the email to SMS gateways to the major wireless providers. Save the file as smsclient,php and put it in the Hacks directory with the class.jabber.php.

The values defined for each cell-phone network work at the time of this writing, but keep in mind that mergers and other changes to the volatile business landscape of the wireless carriers may cause these values to change. You may have to retrieve updated information from your carrier’s website.

It interesting to note that we need to know the carrier in advance. In light of recent laws allowing users to keep their cell numbers when switching carriers, there is really no way to store this information. We can optionally choose to blast the message out to all carriers. That’s a kind of sloppy solution, but then again, this is a hack.

Add the jabber account you are using to connect with the script to your personal jabber account contact list.
Run the script from the command line..

php smsclient.php &

Messages to be sent to a cell phone will take the following format:

SMS:10digitnumber Subject Body

Don’t add any spaces, hyphens or parentheses to the ten digit number.

That’s about it. Happy texting.

The Code
< ?php

/* CONFIG VARIABLES */

// jabber server you are registed at
// jabber server you are registed at
$SERVER = 'yourserver';
//username and password for your special account
$USERNAME = 'yourusername';
$PASSWORD = 'yourpassword';
// jabber id for your personal account
$PERSONAL = 'username@yourserver';
//these values may change
global $cingular;
global $verizon;
global $nextel;
global $tmobile;
global $ATT;
$cingular = '@cingularME.com';
$verizon = '@vtext.com';
$nextel = '@messaging.nextel.com';
$tmobile = '@tmomail.com';
$ATT = '@mmode.com';
//store any numbers and their carriers here
global $cell;
//put any ten digit number and the carrier corresponding
// to the globals above as name-value pairs here
//e.g "2125551234" => “cingular”
$cell = array(
“10digitnumber” => “carrier”
);
/* END CONFIG */

function send($to, $msg) {
global $JABBER;
$JABBER->SendMessage(”$to”,”normal”, NULL, array(”body” => htmlspecialchars($msg)),$payload);
}

//overrides jabber.class.php handler
function Handler_message_normal($message) {
global $JABBER;
$body = $JABBER->GetInfoFromMessageBody($message);
if (substr ($body ,0,3) == SMS) {
$bodyparts = explode(”:”, $body);
$tokenparts = $bodyparts[1];
$tokens = explode(” “, $tokenparts, 3);
$num = $tokens[0];
$sub = $tokens[1];
$bod = $tokens[2];
sms($num, $sub, $bod);
}
}

function sms($number, $subject, $body) {
global $cingular;
global $verizon;
global $nextel;
global $tmobile;
global $ATT;
global $cell;
switch($cell[$number]) {
case “cingular”:
$suffix = $cingular;
break;
case “verizon”:
$suffix = $verizon;
break;
case “nextel”:
$suffix = $nextel;
break;
case “tmobile”:
$suffix = $tmobile;
break;
case “ATT”:
$suffix = $ATT;
break;
}
$address = $number.$suffix;
mail($address, $subject, $body);
echo $address.$subject.$body;
}

function Handler_message_chat($message) {
Handler_message_normal($message);
}

require(”class.jabber.php”);
$JABBER = new Jabber;
$JABBER->server = $SERVER;
$JABBER->port = “5222″;
$JABBER->username = $USERNAME;
$JABBER->password = $PASSWORD;
$JABBER->resource = “smsclient.php”;
$JABBER->enable_logging = FALSE;
$JABBER->Connect() or die(”Couldn’t connect!”);
$JABBER->SendAuth() or die(”Couldn’t authenticate!”);
$JABBER->SubscriptionAcceptRequest($PERSONAL);
while(true) {
$JABBER->SendPresence(NULL, NULL, “online”);
$JABBER->CruiseControl(15 * 60);
}

// may never get here but. . .
$JABBER->Disconnect();

?>

Mar 17 2007 11:26 am | Uncategorized |

2 Responses to “Sending mobile text messages from your Instant Messenger”


  1. […] Sending mobile text messages from your Instant Messenger […]

  2. on 19 May 2008 at 12:01 pm johanna

    i wanna know its is possible as the same way that the sms get in the instnat message ????
    what is the way to have the text mes in the email???

Leave a Reply