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.

:) 02 Dec, 2009
Comments (36)
  • IRCTC Tatkal ticket booking script required...

    By asker on 03 Feb, 2014
  • Hi,

    As of today the way2sms website has changed the div id dynamically using javascript instead of static div id “MobNo”. So we couldnt retrieve that mobile no div id to send sms from this script.

    Hence we are getting the error:
    There is no form with the requested fields at /usr/bin/sms line 118
    Can’t call method “value” on an undefined value at /usr/share/perl5/WWW/Mechanize.pm line 1407.

    Solution:
    If somebody knows the perl, then they may try to fix this issue, by extracting the javascript function and get the value of the var called “rqMob”. In js, they are storing the dynamically generated div id name into the var rqMob. So once we will get to access this var “rqMob”, then we can just replace the “MobNo” with the value of var “rqMob”

    So can anyone help me please......................

    By ramya victor on 04 Feb, 2013
  • 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
    • Thanks bhatrix for the patch.

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

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

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

      On Linux? Make sure the file has executable permissions, run chmod +x sms.pl
      By digitalpbk on 15 Jul, 2011
  • 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
    • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • can i get the updated script

    Can u give the updated script for way2sms sending

    By Anonymous on 19 Jul, 2010
  • 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
    • Version of www::mechanize

      can you post more details like perl and mechanize version ?
      By digitalpbk on 08 Jul, 2010
  • 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
    • 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
  • 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
  • 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
  • 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
  • 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
    • 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
  • 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
    • 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
  • Thanks a lot for keeping this page updated

    Thanks a lot for keeping this page updated

    By Anonymous on 02 Mar, 2010
  • 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
  • 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
    • I think it was a network

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

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

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

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

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

        DK

        By Anonymous on 17 Feb, 2010
  • Mechanize Version?

    What version of Mechanize are you runnning ?
    By digitalpbk on 14 Dec, 2009
  • 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
You may also like
Tags
On Facebook
Email Newsletter