You're sitting at a table with your cow-orkers while the head beancounter goes through his drone about how the bar on the chart for last quater is clearly larger than the bar for the quarter before, and you're starting to wonder if you can slip a certain almond-tasting chemical into the beancounter's coffee.

No worry. You covertly slip your 802.11-enabled PDA out of your pocket and browse to your web server, where you've kept the CGI below for this very situation. Not long after, you receive an SMS on your cell telling you about some emergency or other. You glance at your phone, bolt out of the room, and take an early lunch.

This CGI is for use under mod_perl2, but it shouldn't be hard to modify for regular CGI use.

The send_sms() routine gets a string containing the message to send, and returns true on success, false on failure. It's coded to use Sprint's web form for sending the message. You'll have to change it for your provider. See also: WWW::SMS.

The constant MESSAGES is an arrayref containing the messages to send. Be sure they are <= 160 chars (SMS limit). You can set which message to send with the 'emg' parameter ("emg=0" is the first message, "emg=1" is the second, etc.). The first message is used by default.

You'll need to replace the TO and FROM constants with your phone number.

#!/usr/bin/perl use strict; use warnings; use constant TO => 'xxxx'; use constant FROM => 'xxxx'; use constant MAX_CHARS => 160; use constant PAGE => ' +mpose'; use constant AGENT => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041118 +' . 'Firefox/1.0'; use constant MESSAGES => [ # Each message must be <= 160 chars (SMS l +imit) 'Run away', ]; sub send_sms { my $msg = shift; use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->get( PAGE ); $mech->submit_form( form_name => 'composeForm', fields => { phoneNumber => TO, callBackNumber => FROM, message => $msg, characters => MAX_CHARS - length($msg), }, ); return $mech->success(); } { use Apache::RequestUtil; my $r = Apache->request; my %in = $r->args(); my $msg_num = $in{emg} || 0; send_sms( substr( MESSAGES->[$msg_num], 0, 160 ) ) or die "Couldn't send message\n"; $r->content_type( 'text/plain' ); $r->print( MESSAGES->[$msg_num] ); }

Update: Added ikegami's change to make sure send_sms() never gets a message over 160 chars.

Update (2): Added readmore tags.

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.