02 Dec, 2009

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

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 28th October 2011. 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='..\/Login1.action' 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.

:)
Comments (34) Post a comment
  • changes in Way2sms site

    Hi,

    Due to the new changes in Way2sms site your may module error out as follows:

    Error POSTing http://wwwl.way2sms.com/auth.cl: Not Found:

    Change your code as follows to work fine:

    < $dest =~ s/<form name="loginForm"/<form action='..\/auth.cl' name="loginForm"/ig;

    > $dest =~ s/<form name="loginForm"/<form action='..\/Login1.action' name="loginForm"/ig;

    By bharthix on 28 Oct, 2011 Reply
    • Thanks bhatrix for the patch.

      By digitalpbk on 28 Oct, 2011 Reply
  • how to use it .. its giving

    how to use it .. its giving me as permision denied

    By Anonymous on 15 Jul, 2011 Reply
    • chmod +x sms.pl

      On Linux? Make sure the file has executable permissions, run chmod +x sms.pl
      By digitalpbk on 15 Jul, 2011 Reply
  • this script works

    this script works great......:)).... but is there a way to remove via way2sms.com from our message?????

    By Anonymous on 16 Jun, 2011 Reply
    • No, you cant remove the SMS footer

      You cant remove that message, as it is added by the way2sms service. :)
      By digitalpbk on 16 Jun, 2011 Reply
  • pls update the script i got

    pls update the script i got the following error pls update teh sctipt

    6
    Fetching...
    Loggin...
    Sending ...
    There is no form with the requested fields at perl.pl line 65
    Can't call method "value" on an undefined value at /usr/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm line 1403.

    By Anonymous on 12 Mar, 2011 Reply
  • error on 17th Feb 2011 with Updated code on 25th Apr 2010

    When sms.pl is executed the following error is appearing...

    10
    Fetching...
    Loggin...
    Sending ...
    There is no form with the requested fields at sms_original.pl line 65
    Can't call method "value" on an undefined value at /usr/lib/perl5/site_perl/5.8.5/WWW/Mechanize.pm line 1403

    Please fix this issue...
    I think recently some chages are made in way2sms site

    By Anonymous on 17 Feb, 2011 Reply
  • way2sms perl script error

    Using the latest script but I'm getting the following error

    There is no form with the requested fields at sms.pl line 64
    Can't call method "value" on an undefined value at /usr/lib/perl5/site_perl/5.8.5/WWW/Mechanize.pm line 1403.

    By Anonymous on 29 Sep, 2010 Reply
  • Thanks buddy..........Its working fine......

    Hi,
    this is cooll..will u please write a script to send sms using 160by2.com

    By rammanokar on 23 Sep, 2010 Reply
  • Excellent code.. it works like charm

    Hi,
    At first it didn't work for me even.
    Observed the same errs that are posted here.

    It got resolved upon changing url in the perl script
    http:/ /wwwl .... to http:/ /wwwo...

    It depends on the way2sms servers to which we're re-directed. A million thanks.. man

    By darknight on 15 Sep, 2010 Reply
  • SMS Gateway URL HTTP SMPP

    Send sms via HTTP request, sample url:
    Your can use curl function to open url.

    http://<span>a</span>dforte.com/jovi.member.app-user-commands?action=send&user=youruser&password=yourpas&phone=+12345678&sender=yourcompany&text=test%20message

    By Adforte Sia on 28 Aug, 2010 Reply
  • can i get the updated script

    Can u give the updated script for way2sms sending

    By Anonymous on 19 Jul, 2010 Reply
  • 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.

    By Anonymous on 08 Jul, 2010 Reply
    • Version of www::mechanize

      can you post more details like perl and mechanize version ?
      By digitalpbk on 08 Jul, 2010 Reply
  • 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..

    By Kiran on 23 Apr, 2010 Reply
    • Updated code

      Hi .. The code has been updated to follow the change on way2sms. The script should be working now.
      By digitalpbk on 24 Apr, 2010 Reply
  • 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.

    By Surya on 23 Apr, 2010 Reply
  • 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.

    By raj on 22 Apr, 2010 Reply
  • 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…

    By yroma on 31 Mar, 2010 Reply
  • 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.

    By Anonymous on 28 Mar, 2010 Reply
    • 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. :) 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.
      By digitalpbk on 29 Mar, 2010 Reply
  • 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?.

    By club penguin on 22 Mar, 2010 Reply
    • Try reinstalling PERL

      Which OS is this ? On debian like operating systems, use apt-get remove perl apt-get install perl
      By digitalpbk on 22 Mar, 2010 Reply
  • Thanks a lot for keeping this page updated

    Thanks a lot for keeping this page updated

    By Anonymous on 02 Mar, 2010 Reply
  • Thanks a lot for keeping this page updated

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

    By Anonymous on 02 Mar, 2010 Reply
  • 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.

    By Anonymous on 22 Feb, 2010 Reply
    • I think it was a network

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

      By Anonymous on 23 Feb, 2010 Reply
    • Even i face with the same

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

      By Anonymous on 23 Apr, 2010 Reply
  • 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.

    By Anonymous on 16 Feb, 2010 Reply
    • Filled in username and password ?

      Hi The script is updated now. Please check if you have filled in your username and password also. Thanks.
      By digitalpbk on 17 Feb, 2010 Reply
      • working fine

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

        DK

        By Anonymous on 17 Feb, 2010 Reply
  • Mechanize Version?

    What version of Mechanize are you runnning ?
    By digitalpbk on 14 Dec, 2009 Reply
  • 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?.

    By Kumar K on 14 Dec, 2009 Reply
You may also like



Email Newsletter
Email:
Popular Posts
Recent Posts
Tags
Random photo
Makruzz Cruise Vessel Makruzz Cruise Vessel in Havelock Island Andaman
On Facebook
Recent Comments


digitalpbk