PHP Code for Sending free SMS through your way2sms account executed and working codeUPDATED(5-5-2015)
PHP Code for Sending free SMS through your way2sms account executed and working code
UPDATED(5-5-2015)
Hello friends i am Ravi kumar.J a freelancer web programmer i wrote an
application in PHP with requirements to send a SMS to mobiles without
logging in way2sms service.
when i googled i got many codes related to way2sms which sends free sms
through our own application page which properly working with the old
version of way2sms.Most of them are not working to the new revised
way2sms services. Based on the current requirements i wrote a new PHP
application.
This is code is
executed in my application,by entering the values like way2sms
username, password,receiver mobile number and message(up to 140
characters) in index.html page automatically sends the messages from
your way2sms account to mobiles.
Some Points to Remember...
1.Their should be a registered way2sms account for sender.
2.Cookie file must have full READ and WRITE permission. Give 777 permission in Linux and full read write permission in windows.
3.Do not include '0' or '+91' before mobile number.
4.maximum message limit is upto 140 characters.
Testing the application:
1.Browse the index.html the following window will appear just enter the desired values.

The resultant output would be like this:

Program code:
1.example.php
2.index.html
3.class.sms.php
4.class.curl.php
5.cprint.php(it is optional meant for console printing)
6.cookies.txt
Code follows:
1.example.php
<?php
error_reporting(E_ALL);
ob_implicit_flush(true);
include_once "class.curl.php";
include_once "class.sms.php";
include_once "cprint.php";
$smsapp=new sms();
$smsapp->setGateway('way2sms');
$myno=$_POST['fromno'];
$p=$_POST['pass'];
$tonum=$_POST['tono'];
$mess=$_POST['message'];
cprint("Logging in ..\n");
$ret=$smsapp->login($myno,$p);
if (!$ret) {
cprint("Error Logging In");
exit(1);
}
print("Logged in Successfully\n");
print("Sending SMS ..\n");
$ret=$smsapp->send($tonum,$mess);
if (!$ret) {
print("Error in sending message");
exit(1);
}
print("Message sent");
?>
2.index.html
<html>
<head>
Sending sms from your webpage</head>
<body>
<h1>SEND SMS</h1>
<h1>LOGIN WITH WAY2SMS</h1>
<form action="example.php" method="post">
<table border="1">
<tr><td>
YOUR MOBILE NO:<input type="text" name="fromno" size="10"></td></tr>
<tr><td>PASSWORD:<input type="password" name="pass"></td></tr>
<tr><td>RECEIVER MOBILE NUMBER:<input type="text" name="tono" size="10"></td></tr>
<tr><td>TYPE MESSAGE:<textarea name="message" rows="10" cols="40">TYPE UPTO 140 CHARACTERS ONLY
</textarea></td></tr>
<tr><td><input type="submit" value="sendSMS"></td></tr>
</table>
</form>
</body>
</html>
3.class.sms.php
<?php
include_once "cprint.php";
class sms
{
var $username,$password;
var $curl,$server,$data;
public function __construct()
{
$this->curl=new cURL();
//$this->curl->setProxy("");
$this->data=array();
}
public function setGateway($serverName)
{
switch($serverName)
{
case 'way2sms':
$this->server='way2sms';
break;
default :
print "Currently only Way2sms is supported";
break;
}
}
public function login($username,$password)
{
$server=$this->server;
return(call_user_func(array($this,"login_$server"),$username,$password));
}
public function send($number,$msg)
{
$server=$this->server;
return(call_user_func(array($this,"send_$server"),$number,$msg));
}
private function login_way2sms($username,$password)
{
$html=($this->curl->post("http://www.way2sms.com","1=1"));
if (!preg_match("/Location:(.*)\n/",$html,$matches)) {
print("Error getting domain");
cprint($html);
return(0);
}
$domain=trim($matches[1]);
$this->data['domain']=$domain;
cprint("Domain:$domain");
$html= $this->curl->post(
"${domain}Login1.action",
"username=$username&password=$password&Submit=Sign+in"
);
if (!preg_match('/<h3>Welcome to Way2SMS<.h3>/',$html)) {
print("Error Logging In");
print($html);
return(0);
}
print("Logged In Successfully");
if (!preg_match("/Location:(.*)[?]id=(.*)\n/",$html,$matches)) {
print("Error getting location & token");
cprint($html);
return(0);
}
$referer=trim($matches[1]);
$token=trim($matches[2]);
$this->data['referer']=$referer;
$this->data['token']=$token;
cprint("Referer:$referer");
cprint("Token:$token");
return(1);
}
private function send_way2sms($number,$msg)
{
$domain=$this->data['domain'];
print("Msg:$msg");
$token=$this->data['token'];
$html=$this->curl->post(
"{$domain}main.action?section=s",
"vfType=register_verify&Token=${token}",
$this->data['referer']
);
$msg=urlencode($msg);
$html=$this->curl->post(
"{$domain}smstoss.action",
"ssaction=ss&Token=${token}&mobile=$number&message=$msg"
);
if (!preg_match('/Message has been submitted successfully/',$html)) {
print("Error in sending sms");
print($html);
return(0);
}
else {
echo "<script type=\"text/javascript\">alert('SMS Successfully sended');</script>";
print("sms sended sucessfully");
print("Logged In Successfully");
return(1);
}
}
}
?>
4.class.curl.php
<?php
class cURL {
var $headers;
var $user_agent;
var $compression;
var $cookie_file;
var $proxy;
function cURL($cookies=TRUE,$cookie='cookies.txt',$compression='gzip',$proxy='') {
$this->headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$this->headers[] = 'Connection: Keep-Alive';
$this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$this->headers[] = 'Accept-Language: en-us,en;q=0.5';
$this->headers[] = 'Accept-Encoding gzip,deflate';
$this->headers[] = 'Keep-Alive: 300';
$this->headers[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7';
$this->user_agent = 'iPhone 4.0';
$this->compression=$compression;
$this->proxy=$proxy;
$this->cookies=$cookies;
if ($this->cookies == TRUE) $this->cookie($cookie);
}
function setUserAgent($ua)
{
}
function setProxy($proxy)
{
$this->proxy=$proxy;
}
function cookie($cookie_file) {
if (file_exists($cookie_file)) {
$this->cookie_file=$cookie_file;
} else {
fopen($cookie_file,'w')
or $this->error('The cookie file could not be opened. Make sure this
directory has the correct permissions');
$this->cookie_file=$cookie_file;
fclose($this->cookie_file);
}
}
function get($url) {
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
curl_setopt($process,CURLOPT_ENCODING , $this->compression);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_PROXY, $this->proxy);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($process);
curl_close($process);
return $return;
}
function post($url,$data,$referer=false) {
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
curl_setopt($process, CURLOPT_ENCODING , $this->compression);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_PROXY, $this->proxy);
curl_setopt($process, CURLOPT_POSTFIELDS, $data);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
if($referer)
{
curl_setopt($process, CURLOPT_REFERER, $referer);
}
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($process, CURLOPT_SSL_VERIFYHOST, 2);
$return = curl_exec($process);
curl_close($process);
return $return;
}
function error($error) {
echo
"<center><div style='width:500px;border: 3px solid #FFEEFF;
padding: 3px; background-color: #FFDDFF;font-family: verdana; font-size:
10px'><b>cURL
Error</b><br>$error</div></center>";
die;
}
}
?>
5.cprint.php
<?php
// Print to console
function cprint($str) {
static $debug_2014=-1;
if ($debug_2014===-1) {
if (!empty($GLOBALS["_SERVER"]["DEBUG_2014"])) { $debug_2014=1; }
else { $debug_2014=0; }
}
if ($debug_2014===1) { echo $str,"\n"; }
}
?>
6.cookies.txt
this is empty file
I
Sincerely convey my regards to Govind Jujare who encouraged to write
this blog and his contribution in successfully executing this code.
good application to send sms
ReplyDeletethanks subbu
DeleteIts Working... Thanks for your Efforts...
ReplyDeletethanks vignesh using my code my doubts contact me for mail id ravikumar509@gmail.com
ReplyDeleteThank you so much.. and its working fine..
ReplyDeleteok welcome dude,i will send the updated code if necessary
ReplyDeletethank you so much ravi..for contact personally
ReplyDeletehow to send bulk sms
ReplyDeleteBulk sms is not possible,they have many problems,daily we can send 30 sms one by one or at a time we can send 10 sms's only,that is for free.If any one is DoNotDisturb is activated message will be blocked,Solution is that we need to buy sms packages at that time we can send bulk sms.
Deletehow to send a bulk email...???
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteRemove the cookies from browser and than run
DeleteWarning: include_once(cprint.php) [function.include-once]: failed to open stream: No such file or directory in /home/a2198117/public_html/class.sms.php on line 3
ReplyDeleteHey mayur put the cprint.php file in the same folder the above error wil goes
Deleteok ok but next error is Error getting domain
ReplyDeleteWt domain error just put that errors,maybe yr server problem
Deletehi should i host this on a local server to send sms
ReplyDeleteError getting domain
ReplyDeletefirst install wamp,check wheather it is working or not with sample example, then try this example
Deletei am also have a same problam i am using online server so it is properly working
DeleteThis comment has been removed by the author.
ReplyDeletehow to solve of this type problem Error getting domain ?
ReplyDeletefirst install wamp,check wheather it is working or not with sample example, then try this example
Deletesame problem of Error getting domain. I am using xampp. pl guide
ReplyDeleteIts working proper thanku for this wonderful code.
ReplyDeletethanks for you comments nitesh
Deletehow can i send unlimited message.
ReplyDeleteHello Mr, ravi kumar can you tell me , how can i send unlimited messages.
ReplyDeletekindly reply asp. thanku.
We cannot send unlimited SMS, u want to send bulk SMS u have to buy SMS pack, my app is for sending free SMS I.e upto 30/sms per day
DeleteCan i buy SMS pack from waytosms ?
ReplyDeleteu can buy sms pack again u need to write another php(app) for that application,requirements will changes.
DeleteGood Morrning Mr, ravi if on place of curl_setopt($process, CURLOPT_TIMEOUT, 30); i will apply curl_setopt($process, CURLOPT_TIMEOUT, 60);
ReplyDeleteIs this thing can change sending message quantity, is it right ?
i am not checked for 60 seconds,it is for timeout only it will waits for 30,if 30 will finishes it will timed out,check for 60 nitesh.may be it will long waiting.
Deletei think it is not for quantity
DeleteOkay thanku so much bro.
ReplyDeletethanks for uploading working code.
ReplyDeleteits work into the localhost but not in, web server please help me to send message by using the server !
yogesh it will works in all servers,check it any queries comment me
Deletethis is Error Shows in the domain name :
Delete500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
thank you so much
ReplyDeleteitss working very well
thank you so much
ReplyDeleteitss working very well
Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\sms\class.curl.php on line 59
ReplyDeletehi danish, i think your not enable the curl.php in php.ini file,check once, it will gets
Deletehi i used the app and pressed send sms button but following response appeared in browser:
ReplyDeleteLogged In SuccessfullyLogged in Successfully Sending SMS .. Msg:hello worldError in sending smsHTTP/1.1 302 Found Server: Apache-Coyote/1.1 Location: http://site21.way2sms.com/sendSMS.action Content-Length: 0 Date: Sun, 21 Feb 2016 08:23:26 GMT Connection: close HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Set-Cookie: JSESSIONID=A03~17FA1EB82682203BC7DB61FCD7C807B7.w803; Path=/; HttpOnly Content-Type: text/html;charset=ISO-8859-1 Transfer-Encoding: chunked Content-Encoding: gzip Vary: Accept-Encoding Date: Sun, 21 Feb 2016 08:23:26 GMT Connection: close Error in sending message
pls help
i think may be server problem,otherwise clear the history in all browsers and try it. which server you are using
Deletei think check the internet connection for your system i think it is slow so it is getting problem
DeleteThis comment has been removed by the author.
ReplyDeletei think curl.php problem in your program,enable the curl.php in php.ini file available in server ok
DeleteThis comment has been removed by the author.
ReplyDelete1.Warning: include_once(class.curl.php) [function.include-once]: failed to open stream: No such file or directory in C:\wamp\www\WS\example.php on line 5
ReplyDelete2.Warning: include_once() [function.include]: Failed opening 'class.curl.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp\www\WS\example.php on line 5
3.Warning: include_once(class.sms.php) [function.include-once]: failed to open stream: No such file or directory in C:\wamp\www\WS\example.php on line 6
4.Warning: include_once() [function.include]: Failed opening 'class.sms.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp\www\WS\example.php on line 6
5.atal error: Class 'sms' not found in C:\wamp\www\WS\example.php on line 9
These 5 errors are shown when I Run the codes.What modification is needed to execute properly.
i think may be u have to enable the curl.php in php.ini file, some of the above files are missing put all files in same folder and try
Deletethank u :-)
ReplyDeletehow can i use this code for lamp server.?..its not sending the message. I feel there is problem to login.
ReplyDeleteplz help me through this..its part of my project to send sms.
ok, where exactly problem in login,check it and post the errors and warnings
Deleteon saturday and sunday i will free, ok i will check on those days
Deletethis code worked fine in windows installed xampp server...as i checked in ubuntu installed lamp server(Apache2) the same code,its isn't working!
DeleteAnd there is no error to debug too..I have no idea where its going wrong!
Sorry i also dont have idea on ubuntu installed servers
DeleteAWESOME SCRIPT BRO WORKING ON LOCAL SERVER AS WELL
ReplyDeleteThanks for comments
DeleteThanks for comments
DeleteThis comment has been removed by the author.
ReplyDeleteSir I got the following error
ReplyDeletePHP Error Message
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a6651060/public_html/class.curl.php on line 71
Free Web Hosting
Error Logging InHTTP/1.1 302 Found Server: Apache-Coyote/1.1 Set-Cookie: JSESSIONID=A04~07DD32AA702BA2F70317758493DA75FC.w804; Path=/; HttpOnly Location: http://site24.way2sms.com/ebrdg.action;jsessionid=07DD32AA702BA2F70317758493DA75FC.w804?id=07DD32AA702BA2F70317758493DA75FC.w804 Content-Length: 0 Date: Sat, 28 May 2016 05:14:50 GMT Connection: close
please help
which server you are using, disable the safe mode in that server
ReplyDeleteThank you sir. But, I don't know how to do that. I am using www.000webhost.com.
DeletePlease guide me.
This comment has been removed by the author.
DeleteError Logging InHTTP/1.1 302 Found Server: Apache-Coyote/1.1 Location: http://site24.way2sms.com/vem.action?id=0285E550FEDC9CF361F4D06C3CB1FB73.w810 Content-Length: 0 Date: Thu, 30 Jun 2016 09:29:39 GMT Connection: close HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/html;charset=ISO-8859-1 Transfer-Encoding: chunked Content-Encoding: gzip Vary: Accept-Encoding Date: Thu, 30 Jun 2016 09:29:39 GMT Connection: close
ReplyDeleteThank you sir!!
ReplyDeleteCall to undefined function curl_init() in C:\wamp\www\SMS2\class.curl.php on line 59
ReplyDeletefor some numbers it is going for some mobile numbers it is not going ? why ?
ReplyDelete
ReplyDeletesir it showing the following error
plz help me
Error Logging InHTTP/1.1 302 Found Server: Apache-Coyote/1.1 Set-Cookie: JSESSIONID=A05~14456DCF90070C9455C39EE7B417520E.w805; Path=/; HttpOnly Location: http://site24.way2sms.com/main.action;jsessionid=14456DCF90070C9455C39EE7B417520E.w805?Token=14456DCF90070C9455C39EE7B417520E.w805§ion=s Content-Length: 0 Date: Wed, 24 May 2017 06:06:04 GMT Connection: close HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/html;charset=UTF-8 Transfer-Encoding: chunked Content-Encoding: gzip Vary: Accept-Encoding Date: Wed, 24 May 2017 06:06:04 GMT Connection: close
it makes error getting domoian error what i do
ReplyDeleteThanks for your feedback
ReplyDeleteThanks for your feedback
ReplyDeleteError Logging InHTTP/1.1 302 Found Server: Apache-Coyote/1.1 Location: http://site21.way2sms.com/main.action?Token=093CCF49C067EFFB4295EFDACBFBD1A5.w803§ion=s Content-Length: 0 Date: Tue, 23 Jan 2018 16:31:16 GMT Connection: close HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/html;charset=UTF-8 Transfer-Encoding: chunked Content-Encoding: gzip Vary: Accept-Encoding Date: Tue, 23 Jan 2018 16:31:16 GMT Connection: close
ReplyDeleteTry MsgClub SMS API is pretty simple . HTTP API is most popular API. It is allows you to Integrate SMS API PHP services into your own System/application for better functionality required by you.
ReplyDeleteNice blog. MsgClub SMS API PHP send a text message directly from your own software, website or application which developed using php code is now gets possible. Your search for sending information from a reliable and robust application will get end here because MsgClub is helping api users.
ReplyDeleteBulk SMS API