Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Sending SMS msgs to AT&T phone / Coping with forms that want cookies

by dws (Chancellor)
on Jun 28, 2002 at 16:50 UTC ( #178065=snippet: print w/replies, xml ) Need Help??
Description: A simple, anti-bot defensive measure that some sites have put together requires that a POST request be accompanied by a session cookie presented when the form was retrieved. AT&T Message Center uses this technique. The following fragment demonstrates how to work through this barrier and send SMS message to AT&T subscriers.

Please use this responsibly.

# 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 = "";
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();

# 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";
  • Comment on Sending SMS msgs to AT&T phone / Coping with forms that want cookies
  • Download Code
Replies are listed 'Best First'.
Re: Sending SMS msgs to AT&T phone / Coping with forms that want cookies
by Anonymous Monk on Jul 17, 2002 at 16:21 UTC
    I did something simalur to this but added an option in SendMail to redirect an email address to the script. This way I could have email paging. Just Ideas!!!!!!!!!!!
    /etc/aliases pagebrad: "| /usr/bin/" --------------------------------------- /usr/bin/ while (<STDIN>) {$org_msg .= $_}; $org_msg =~ /([Ss]ubject: )(.*)/; $msg = $2 if $2; $org_msg =~ /([Ff]rom: )(.*)/; $from_field = $2 if $2; $URL = ''; use HTTP::Request::Common qw(POST); use LWP::UserAgent; $ua = new LWP::UserAgent; my $req = POST $URL, [ PIN => $pgr_num, From => $from_field, Subject => $subj, Message => $msg, tr => "PinSend", page_name => "Phnximg" ];
      hiiiiiiiiiiii did u receive my msg? take care byeeeeeeeeeeee
Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: snippet [id://178065]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2023-12-06 21:05 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (32 votes). Check out past polls.