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.
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.
processing...Welcome to Webmonkey
- edit articles
- add to the code library
- design and write a tutorial
- comment on any Webmonkey article
Sign In Information Sent
Send an sms using Perl
/skill level/
/viewed/
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.
/related_articles/
Special Offer For Webmonkey Users
WIRED magazine:
The first word on how technology is changing our world.