O'Reilly logo

PHP Hacks by Jack D. Herrington

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #93. Send SMS Messages from Your IM Client

Use PHP to send SMS messages to a cell phone from Jabber messages from your instant messenger client.

One of the most useful features of instant messaging is the availability of user presence (knowing whether a user is online). Of course, if a user is unavailable and you really want to get a message to him, it would probably be really cool if you could send the message to his 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 a user's cell phone, and this hack shows how to do just that, by using an email-to-SMS gateway (something almost all major phone providers already have in place).

The Code

Save the code in Example 9-12 as smsclient.php.

Example 9-12. An SMS client in PHP

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required