# This code fragment demonstrates how to send an SMS text message to # an AT&T wireless subscriber who has an SMS-enabled cell phone. This # can be used to send an SMS message to yourself when certain events # happen on your server/website. # # At present, AT&T message center presents a browser with a cookie # when the SMS message form is retrieved, and won't send an SMS # message unless the cookie is presented along with the POST to # their CGI. Below we use HTTP::Cookies to set up a cookie jar to # hold the cookie, and present it along with the post. # # There are a number of SMS packages on CPAN, and they're worth # exploring. At the time I put this together, I didn't find anything # there that coped with the cookie requirement. # # Please use this responsibly. # # 28 June 2002 Dave W. Smith use HTTP::Request::Common qw(GET POST); use HTTP::Cookies; use LWP::UserAgent; my $messageCenter = "http://www.mobile.att.net/messagecenter"; my $pagersend = "$messageCenter/pagersend.cgi"; # ---- change these as appropriate ---- my $phoneNumber = die "phone number here"; my $msgFrom = "me"; # name or phone number my $msgSubject = "Test"; # optional subject my $msgBody = "Hello World!"; # from + subject + body <= 140 chars # ------------------------------------- # Set up a UserAgent with a cookie jar my $ua = new LWP::UserAgent(); my $cookies = new HTTP::Cookies(); $ua->cookie_jar($cookies); # Get the pager request form. This gets the cookie we'll need # later to send the message. my $req = GET "$messageCenter/"; my $response = $ua->request($req); if ( ! $response->is_success() ) { die "Couldn't get form from message center"; } # Send the SMS message $req = POST $pagersend, [ pin => $phoneNumber, from => $msgFrom, subject => $msgSubject, message => $msgBody ]; $response = $ua->request($req); if ( ! $response->is_success() ) { die "Can't submit page request"; } my $content = $response->as_string(); if ( $content !~ m/your message has been submitted/i ) { die "Server didn't like page request\n"; } print "Sent\n";