Member Sign In
Not a member?

A Wired.com user account lets you create, edit and comment on Webmonkey articles. You will also be able to contribute to the Wired How-To Wiki and comment on news stories at Wired.com.


It's fast and free.

Webmonkey is a property of Wired Digital.
processing...
Join Webmonkey

Please send me occasional e-mail updates about new features and special offers from Wired/Webmonkey.
Yes No

Please send occasional e-mail offers from Wired/Webmonkey affiliated web sites and publications, and carefully selected companies.
Yes No

I understand and agree that registration on or use of this site constitutes agreement to Webmonkey's User Agreement and Privacy Policy.
Webmonkey is a property of Wired Digital.
processing...

Retrieve Sign In

Please enter your e-mail address or username below. Your username and password will be sent to the e-mail address you provided us.

or
Webmonkey is a property of Wired Digital.
processing...

Welcome to Webmonkey

A private profile page has been created for you.
As a member of Webmonkey, you can now:
  • edit articles
  • add to the code library
  • design and write a tutorial
  • comment on any Webmonkey article
Close
Webmonkey is a property of Wired Digital.

Sign In Information Sent

An e-mail has been sent to the e-mail address registered in this account.
If you cannot find it in your in-box, please check your bulk or junk folders.
Sign In
Webmonkey is a property of Wired Digital.

Send an sms using Perl

/skill level/
/viewed/
0 Times

Contents

Introduction

Ever wanted to enable your Perl script to communicate via SMS? By using Net::SMS::2Way you can achieve this.

This tutorial will show you a quick and easy way to do this.

What you'll need

You'll need to register an account at [1]. I'd suggest you buy some credits as well.

You'll need to have the Net::SMS::2Way install. You can have a look at [2]

Steps

Create the config file

Create a configuration file, /etc/sms.cfg, which looks like this:

verbose = 1
logfile = /var/log/sms.log
username = jbloggs
password = MyPa55w0rd

Please note that the username and password is your bulksms.com user and password.

The Code

In your script you can add the following to import the Net-SMS-2Way module and create the object. Put this somewhere near the top:

use Net::SMS::2Way;

my $sms = Net::SMS::2Way->new({config => '/etc/sms.cfg'}) || die "FATAL: Could not create Net::SMS::2Way object!\n";

The method that actually sends the SMS, send_sms(), is called like this:

my $resp = $sms->send_sms('This is the SMS message!', '27851234567');

if ($sms->{error}) {
  warn "There was an error sending SMS: " . $sms->{error} . "\n";
}

You should check the log file (specified in the config file) for errors/warnings if you are having problems.

Notes

1. This example is for the South African implementation of Net::SMS::2Way. To use the US or UK sites, please change your configuration file accordingly e.g.

country = UK

Read the Net::SMS::2Way docs for more examples.

2. Make sure that the path you specified for logfile in the config file is writable by the users who will be executing the script.

Suggested readings

Please read the Net::SMS::2Way documentation at [3]

You can also read my other tutorial on this module at [4]

  • This page was last modified 13:14, 10 July 2008.
Edit this article
Reddit Digg
 
Subscribe now

Special Offer For Webmonkey Users

WIRED magazine:
The first word on how technology is changing our world.

Subscribe for just $10 a year