#!/usr/bin/perl use strict; use warnings; use constant TO => 'xxxx'; use constant FROM => 'xxxx'; use constant MAX_CHARS => 160; use constant PAGE => 'http://messaging.sprintpcs.com/textmessaging/compose'; 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 limit) '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] ); }