Perl Script to send Free SMS to any mobile number in INDIA using way2sms

2009
02
Dec
22

The following script sends SMS to any number in INDIA using the free service provided by Way2Sms.com
Requires WWW::Mechanize and Compress::Zlib libraries.

Please remember to fill the username and password in the fields that is mentioned in the script.

Updated code on 25th April 2010. If you face errors use the new script.

#!/usr/bin/perl
 
use WWW::Mechanize;
use Compress::Zlib;
 
my $mech = WWW::Mechanize->new();
 
my $username = ""; #fill in username here
my $keyword = "";  #fill in password here
 
my $mobile = $ARGV[0];
my $text = $ARGV[1];
 
$deb = 1;
 
print length($text)."\n" if($deb);
 
$text = $text."\n\n\n\n\n" if(length($text) < 135);
 
$mech->get("http://wwwl.way2sms.com/content/index.html");
unless($mech->success())
{
	exit;
}
$dest = $mech->response->content;
 
print "Fetching...\n" if($deb);
 
if($mech->response->header("Content-Encoding") eq "gzip")
{
	$dest = Compress::Zlib::memGunzip($dest);
	$mech->update_html($dest);
}
 
$dest =~ s/<form name="loginForm"/<form action='..\/auth.cl' name="loginForm"/ig;
 
 
$mech->update_html($dest);
$mech->form_with_fields(("username","password"));
$mech->field("username",$username);
$mech->field("password",$keyword);
 
print "Loggin...\n" if($deb);
 
$mech->submit_form();
 
$dest= $mech->response->content;
 
if($mech->response->header("Content-Encoding") eq "gzip")
{
        $dest = Compress::Zlib::memGunzip($dest);
        $mech->update_html($dest);
}
 
$mech->get("http://wwwl.way2sms.com//jsp/InstantSMS.jsp?val=0");
$dest= $mech->response->content;
if($mech->response->header("Content-Encoding") eq "gzip")
{
        $dest = Compress::Zlib::memGunzip($dest);
        $mech->update_html($dest);
}
 
print "Sending ... \n" if($deb);
 
$mech->form_with_fields(("MobNo","textArea"));
$mech->field("MobNo",$mobile);
$mech->field("textArea",$text);
$mech->submit_form();
 
if($mech->success())
{
print "Done \n" if($deb);
}
else
{
print "Failed \n" if($deb);
exit;
}
 
$dest =  $mech->response->content;
if($mech->response->header("Content-Encoding") eq "gzip")
{
        $dest = Compress::Zlib::memGunzip($dest);
		#print $dest if($deb);
}
 
if($dest =~ m/successfully/sig)
{
  print "Message sent successfully" if($deb);
}
 
exit;
#EOF

Usage

./sms.pl mobile number "message"

Example:
./sms.pl 9000012345 "Hey there does this work?"

Happy SMSing.

Warning

This script is not affiliated or has anything to do with Way2Sms.com. This piece of code is provided AS IS without any warranty. Usage of this script is solely upto you. WAY2SMS will not be happy about you using this script skipping their ads.

Enjoy SMSing...
Smiling

Similar Posts
Related Searches




Comments

can i get the updated script

Can u give the updated script for way2sms sending

Plz check this error msg which i am getting...........

Can't locate object method "update_html" via package "WWW::Mechanize" at C:\way2
sms.pl line 38.

Version of www::mechanize

can you post more details like perl and mechanize version ?

Error Status - Dono wat exactly it means

[kiran@localhost Perl]$ ./sms.pl 974xxxx217 "hello how are u"
15
Fetching...
Loggin...
Sending ...
There is no form with the requested fields at ./sms.pl line 65
Can't call method "value" on an undefined value at /usr/lib/perl5/vendor_perl/5.8.8/WWW/Mechanize.pm line 1243.

can you tell me what could be the problem. am using FC8

I have set my selinux to permissive mode..

Updated code

Hi .. The code has been updated to follow the change on way2sms. The script should be working now.

I am getting the following

I am getting the following error message.

I hope I don't have any network issues as I am able to send SMS via way2sms

Here is the program output

C:\My Data\personal\Personal>perl sms.pl 9500012345 test
4
Fetching...
Loggin...
Sending ...
There is no form with the requested fields at sms.pl line 65
Can't call method "value" on an undefined value at C:/Perl/lib/WWW/Mechanize.pm
line 1348.

Please help me to get out of this issue.

Error while running the script

Hey, I am getting this error when i try to send a messge
There is no form with the requested fields at ./sms.pl line 65
Can't call method "value" on an undefined value at /usr/share/perl5/vendor_perl/WWW/Mechanize.pm line 1348.

it works

Yes, I have already inform it to my indian friend and he told me that it works! he sends his regards and thanks…

CGI

Hey.. would you consider wrapping this up in a CGI script so it can be deployed on the web? The script works great, BTW.. I'm automating some things with it.

Way2SMS

Way2sms provides a free SMS service and they rely on ads to get the revenue back, deploying this on the web is with CGI would make things too easy for people and destructive for Way2SMS. It is possible to deploy on CGI but I think it would be unethical to do so. Smiling

Consider buying one of the commercial SMS packages if you are using SMS for application, it would be very cheap.

The script above is just for personal and educational use only.

I'm getting the following

I'm getting the following Error while running the program.

"perl: relocation error: /user/kumark/perl/perl_modules/lib64/perl5/site_perl/5.8.0/auto/HTML/Parser/Parser.so: undefined symbol: Perl_Tstack_sp_ptr"

Can you please help me?.

Try reinstalling PERL

Which OS is this ?

On debian like operating systems, use

apt-get remove perl 
apt-get install perl

Thanks a lot for keeping this page updated

Thanks a lot for keeping this page updated

Thanks a lot for keeping this page updated

Thanks a lot for keeping this page updated along with changes in way2sms.com

Hey, I am getting this error

Hey, I am getting this error when i try to send a messge
There is no form with the requested fields at ./sms.pl line 65
Can't call method "value" on an undefined value at /usr/share/perl5/vendor_perl/WWW/Mechanize.pm line 1348.

Even i face with the same

Even i face with the same error .. so how to resolve it?

I think it was a network

I think it was a network problem, it works fine now..

Not receiving sms

Hi,

I tried to run above code from the linux machine. I got below output.

18
Fetching...
Loggin...
Sending ...
Done
Message sent successfully

But i didnt receive the message to my mobile. I would appreciate your help.

DK.

Filled in username and password ?

Hi
The script is updated now.
Please check if you have filled in your username and password also.

Thanks.

working fine

Thank you. With the updated script it is working fine,

DK

Mechanize Version?

What version of Mechanize are you runnning ?

Getting an Error while running the above code

Hi,
I'm getting the following Error while running the program.

"perl: relocation error: /user/kumark/perl/perl_modules/lib64/perl5/site_perl/5.8.0/auto/HTML/Parser/Parser.so: undefined symbol: Perl_Tstack_sp_ptr"

Can you please help me?.

Post new comment

The content of this field is kept private and will not be shown publicly.