17th Dec ’10 :
Now here’s the deal. 160by2,way2sms and freesms8 offer free SMS and earn money through the ads on their website. By using this PHP script, we are bypassing their website illegally as their ad never gets shown. I hope you will keep this in mind when you use this script. If you want to send free SMS legally, then head over to http://freesmsapi.com and create an account. They are offering an excellent service totally free of cost.
Also the developers at way2sms and freesms8 keep changing their url’s and security methods to prevent such scripts from working (160by2.com guys are cool about this). And as this PHP code published here can be viewed publicly, their jobs become easy. So I will not be able to continue development of the scripts because as soon as I publish the code here, way2sms/freesms8 change their code to break my code.
So there should be a way to restrict access to the PHP code published here so that the code reaches appropriate hands only. Maybe a password protected SVN or forums based on reputation points, I dont know..
Post in your opinions about this as a comment and lets see whether we can work it out together.
Update as of 5th Oct ’10 : Bulk SMS services restored !!
Update as of 24th Sep ’10 : Govt has banned bulk sms temporarily. So all the bulk sms providers have stopped their services. More info. This script will not work till Sep 29th. In the meantime, I will upload the next version of the script which can check internet connectivity, login errors and other responses sent by the gateway. I will also be adding support for freesmsapi.com and freesms8.com gateways.
Update as of 10th Sep ’10: The code has been updated to accomodate a small change in the way2sms website.
Update as of 15th Aug ’10 : The code has been updated to work on all 160by2 and way2sms accounts and also will fetch any error codes being generated by these gateways. If you encounter any bugs, drop in a comment.
This is a PHP script I wrote a while back to automate the sending of SMS/text message using 160by2.com/way2sms.com account.
You can use this PHP API script to send free sms India, Kuwait, Singapore, UAE, Phillipines, Malaysia etc. Very useful if you are combining this with the registration page of your website to verify the users mobile number similar to verification of their email address.
Some possible real world applications of this script are :
1. Email to SMS.
2. Birthday alerts/Daily joke/thought for the day/news SMS
3. Gtalk/XMPP to SMS
Pre-requisites to use this script :
1.You need a hosting server with PHP5 and cURL extension enabled. The server should be able to open socket connections to other servers.
2.a valid,verified 160by2.com account or way2sms.com account (Create an account for free on one of these gateways and send a test SMS through their UI first.)
Example Usage (Also included in example.php):
include_once “class.curl.php”;
include_once “class.sms.php”;$smsapp=new sms();
$smsapp->setGateway(‘way2sms’); // you can set gateway to be 160by2 to use your 160by2 account;
// way2sms code has been tested on different accounts to be stable.echo “Logging in … “;
$smsapp->login(‘username for way2sms’,'password’);echo “Sending SMS … “;
$result=$smsapp->send(’10 digit mobile number’,'Your text message’);if($result)
{
echo “Message sent”;
}
else
{
echo “Error encountered : “.$smsapp->getLastError();
}
Limitations :
1. 160by2.com offers a character limit of around 145 for each message. Way2sms offers a character limit of 140 characters per message. Please see that the character limit is honored.
2. also a limit of 50 messages per day per account and 10 messages per recepient phone number holds good for 160by2.
(27503 hits) SMS API Download |
Demo:
Click here for a simple demo application to send free SMS using this API
I had also written a script using this class to send an sms alert to notify as soon as the booking for an upcoming movie opens up on bookmyshow.com, if someones interested in using this bookmyshow script, drop in a comment.
New SMS API
Supports 160by2, freesmsapi, freesms8. Does not support way2sms as of now.
To send free SMS all over the world using your iPhone/iPod touch, use Textoo Pro app. It is currently the best iphone app to send free unlimited text messages easily.
(13693 hits) PHP SMS API v2.0 Download |
waiting for demo….
demo uploaded. Source code for demo will be rolled out soon.
Logging in … Sending SMS …
Notice: Undefined offset: 1 in D:\Hosting\4907009\html\allsites\pz10\sms\class.sms.php on line 88
Notice: Undefined offset: 1 in D:\Hosting\4907009\html\allsites\pz10\sms\class.sms.php on line 93
Error encountered :
please help in how it works
please tell me where was the login form
I just tested the demo and it worked fine for me. I still need to test the code on my server.
Great work. But it can be the best work if the page takes the person to thank you page instead of keeping him on smsdemo page.
Thanks
Salan
You can change the action attribute for the form to send the user to a new page after the SMS is sent. Right now its in the same page to keep things simple.
I am getting the following error.
Logging in …
Fatal error: Call to undefined function curl_init() in E:\UCan\www\sms-api\class.curl.php on line 48
You will need to enable cURL extension in the PHP.ini file. You will find a lot of tutorials on how to do this. Some good hosting companies enable this by default.
Nice SMS API…Good Stuff
Nice thanx a lot for this
Undefined offset: 1 in C:\wamp\www\SMS\class.sms.php on line 60
Please help
Can you confirm that cURL is enabled and also that you dont need a proxy to connect to the internet ?
Dear Kiran,
I want to get contact list from Yahoo, Gmail, MSN from PHP code. My current project needs that facility. So please help me out.
Thank you for your help.
Hi, Sumit,
It is not very easy to import contact lists from all the providers as they do not provide any API to do this. Although there are a couple of scripts (nonfree) which use cURL to fetch the contacts.
You should try out those
i uploaded the code and i’m getting error as
Logging in … Sending SMS …
Notice: Undefined offset: 1 in xxxxx\class.sms.php on line 88
Notice: Undefined offset: 1 in xxxxx\class.sms.php on line 93
Error encountered :
Today no message from demo and my site Is service stop by 160by2
Please check the demo now.
i want to use smsroaming api (http://smsroaming.com)
frommy website kindly you adujest this api in this scrpit and email me i will b greatfull to you
[email protected]
not working…sorry
Hi Kiren,
Its great article. i have been tried with my project and encounter a one problem.
it will give me array like this
Logging in …
Notice: Undefined offset: 1 in class.sms.php on line 131
Sending SMS …
Notice: Undefined offset: 1 in class.sms.php on line 153
sms Object
(
[username] =>
[password] =>
[curl] => cURL Object
(
[headers] => Array
(
[0] => Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[1] => Connection: Keep-Alive
[2] => Content-type: application/x-www-form-urlencoded;charset=UTF-8
[3] => Accept-Language: en-us,en;q=0.5
[4] => Accept-Encoding gzip,deflate
[5] => Keep-Alive: 300
[6] => Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
)
[user_agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.11) Gecko/20100701 Firefox/3.5.11 (.NET CLR 3.5.30729)
[compression] => gzip
[cookie_file] => cookies.txt
[proxy] =>
[cookies] => 1
)
[server] => 160by2
[loginDone] => 1
[debugMode] => 1
[data] => Array
(
[id] =>
)
[error] =>
)
thanks in advance
Thanks a lot..
I have tried it in 0fees.net free host and was working perfectly.
But now when i switched to x10hosting.com I encountered some errors. cURL is supported in x10hosting but still this error popped up.
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /home/….
In x10hosting forums I found this piece of info :
” It is been that it is disabled on free hosting for obvious reasons.
If you need to redirect, simply use header(“Location: ./folder/location.php”); ”
Can you pls modify the code in such a way that it won’t use the CURLOPT_FOLLOWLOCATION?
Thanks once again..
Hey Afsal,
Please move onto some paid hosting, Most of the free hosting websites which give full privileges are being misused, hence they block network related PHP functions.
You could modify line 53 and 70 in class.curl.php to ‘curl_setopt($process, CURLOPT_FOLLOWLOCATION, 0);’ and give it a try. I think this change should work without problems.
I tried it after modifying as you said. But its not working. I guess i will have to move to paid hosting.
Hey Afsal .. without curl you cannot run this script. But you can use byethost.com has a free host.
Yeah I know that it requires cURL but the byethost free hosting account doesn’t support cURL. But its paid hosting is supporting it.
Hey all, Sorry for the delay. Now the code is working on both way2sms and 160by2 accounts.
Thanks for this, but it is showing this following error:
Logging in …
Notice: Undefined offset: 1 in /home/public_html/sms/class.sms.php on line 73
Sending SMS …
Notice: Undefined offset: 1 in /home/public_html/sms/class.sms.php on line 93
Notice: Undefined offset: 1 in /home/public_html/sms/class.sms.php on line 98
Error encountered :
Hello Kiran,
Thanks for providing the code.
As i am new to PHP,ca you plz help me in setting up the app at my system?
You need a hosting server with PHP5 and cURL extension enabled. The server should be able to open socket connections to other servers
Are you testing it on a local server ?
{
If yes, are you using windows ?
{
Download xampp/wamp and install it. Search for php.ini in the installed directory and open it. Search for the line which says php_curl.dll and remove the semi colon (;) character from the beginning of the line. This will enable cURL on your system. Then put in your scripts to the htdocs folder in the xampp/wamp directory. And then access the example.php file through the browser (http://localhost/example.php)
}
If you are using linux{
You can get lampp for linux from the xampp website and follow the same procedure as above
}
}
Are you testing it on a hosting server {
Most paid hosting servers have cURL enabled if PHP is enabled. So just upload all the php scripts onto a dir on the server using FTP and modify the example.php to put in the username,password. Run the script through your browser.
}
Thanks for the code. A brilliant mind you got there but when I run your code to my localhost I got the following error:
Logging in …
Fatal error: Call to undefined function curl_init() in C:\wamp\www\new1\sms-api\class.curl.php on line 59
Can you help me how to fix this one?
Thanks and hoping for your response…
Hi Dnz, please enable cURL in PHP. Refer other comments for info on how to do it.
The demo doesn’t seem to be working.
Hi, Bazinga, I just tested the demo, and it is working.
Well, it didn’t work for me. I received no message. Although it works PERFECTLY on a server. Thanks a lot.
i uploaded the code and i’m getting error as
Logging in … Sending SMS …
Notice: Undefined offset: 1 in xxxxx\class.sms.php on line 88
Notice: Undefined offset: 1 in xxxxx\class.sms.php on line 93
Error encountered :
plz help me
i am asked u already how to recover this problem
Hi Harmeet, The new code should fix all the errors. Please re download the scripts.
Hello,
I really appreciate your script.
What I am looking for is I would be able to take the mobile no. from the database where the user registered his no., and should throw a msg on the cell with the activation code, asking the user to enter this code on website.
an SMS verification script used while registering on my account.
Waiting…
Anyone pls help on this.
[email protected]
A quick way to do this is to take the first 5 characters of the MD5/SHA1 hash of the mobile number and send it to the user as a SMS. But this is not secure.
So you could generate a random number and store it back into the DB and use it back for verification. This is a better way to verify the number.
I am not sure whether there is any open source script to do this as this kind of verification is normally done only on Indian websites
Hi Kiran,
Nice work man…It works on both way2sms and 160by2..
Cheers
Hey Ani, Thanks dude.
Hi I like to use this api on other gateway like smscountry. as in urs api it needs to logged in with mobile no and password. But i have my user name and password and i am trying to run it with data i have but it always giving error … “Error encountered” and rest is blank.
Thanks
Getting error
Logging in …
Notice: Undefined offset: 1 in C:\xampp\htdocs\SMS\class.sms.php on line 65
Notice: Undefined offset: 1 in C:\xampp\htdocs\SMS\class.sms.php on line 73
Sending SMS …
Notice: Undefined offset: 1 in C:\xampp\htdocs\SMS\class.sms.php on line 93
Notice: Undefined offset: 1 in C:\xampp\htdocs\SMS\class.sms.php on line 98
Error encountered :
Can you verify whether you require a proxy to connect to the internet. Looks like PHP is not able to access their server.
yes i do require proxy to connect…
do i need to make any changes in the code?
You need to edit class.sms.php line 15 and change it to “$this->curl->setProxy(“proxy-address:port”);”
done with the proxy part but still getting error
Logging in … Sending SMS …
Notice: Undefined offset: 1 in C:\xampp\htdocs\SMS\class.sms.php on line 94
Notice: Undefined offset: 1 in C:\xampp\htdocs\SMS\class.sms.php on line 99
Error encountered :
I think it might be because of the govt ban of bulk sms (http://www.ndchronicle.com/news/Govt_extends_ban_on_bulk_SMS__MMS_till_Sep_29_1285307911/)
BTW, which gateway are you using ?
way2sms is giving above error…..
160by2 is working fine result shown as ‘sms sent’…
but sms not receiving may bcoz of the bulk sms ban
will try it again & will update you
I think you should wait till Sep 29th. None of the sms gateways (including freesmsapi , freesms8) is working now. And the script is failing because of an unexpected response given by the gateway.
In the mean time , I will update the script to v2.0 which will fetch the exact error returned by the gateway and it will also have a function for connectivity check.
Fabulous !
keep it up !
How to send free sms with attachments i.e. images .jpg .gif etc. or .mp3 as ring tones.
Thanks
Regards
Hey Sandy,
I am not sure whether it is possible to do that through SMS. You are limited to 160 unicode characters and any data which can be represented within this limit can be sent using these free SMS gateways. But again the receiving end should also support your custom encoding.
Nokia had come up with a way to send monophonic ringtones using this technology(480 characters), but even then, not all other manufacturers supported it.
So if you can come up with some amazing compression method, it should be possible.
I would rather use MMS or email to do this, BTW this script doesnt support free MMS (does any free gateway offer this ? )
Dear KK,
I had uploaded your script and ran it.
It is showing following msg
Logging in … Sending SMS … Message sent
but I had not received any msg from way2sms.
I had typed My login mob no and msg to be sent to mob are same in your example.php
What may be the reason?
Sandy
Way2sms messages get delivered much later compared to 160by2. So you might receive the message after some time. You can try sending a message through their website instead of the script and try it first.
Sorry Dear KK
Your script had successfuly shown up.
When I ran it second time I received the msg instantly.
Sorry to bother you,
Just now I was reading about soap and found nusoap_client_mime client supporting MIME attachments defined at http://www.w3.org/TR/SOAP-attachments. It depends on the PEAR Mail_MIME library
You can research on it for attachments.
You can download from the website http://www.aswinanand.com/2008/07/send-free-sms-web-service/
Thanks
Sandy
Dear KK,
I have separate Form to Fill Mob.no and msg as you have in your demo above.
What additions I have to do, How will i receive these two variable from form post html to inside example.php given by your goodself so that it automatically replaces value in line:-
echo “Sending SMS … “;
$result=$smsapp->send(’10 digit mobile number’,’Your text message’);
Regards,
Sandy
If the number field in your form has the name attribute as ‘mobile’( for e.g <input type=’text’ name=’mobile’ /> ), then you can access it as $_POST['mobile']
So $result=$smsapp->send(’10 digit mobile number’,’Your text message’); will become
$result=$smsapp->send($_POST['mobile'],$_POST['message']);
I am receiving the following error msg.
Logging in …Sending SMS …
Notice: Undefined offset: 1 in /sms/class.sms.php on line 98
Error encountered :
Logging in … Sending SMS … Error encountered : asdhg65653evfd
This is the output i am getting..
Can any one rectify it..?
It works perfectly fine.
Thank you so much !
Oh… So the new version is out.. awesome. thanks buddy.
how can I use this for the applications developed in microsoft technologies(for web application developed in .net)
To make use of this script from other technologies, you need to modify example.php file to make it accept all the required info (mobile no, message) as a GET variable through the URL instead of hardcoding them. This way, you can call this url from .net or java
Dont forget to take care of security.
Thanx, for the information given., plz if you dont mind can u give any example URL to refer? as I m new to PHP.
Sorry,
You will need to have basic knowledge of PHP
So you could learn the basics of php from http://www.php.net , it will hardly take a few hours to implement what you want.
Basically you can modify example.php included in the API to make the variables pass through the url, like $mobileno=$_GET['mobileno']
And then you can pass it through the URL as example.php?mobileno=9xxxxxxxxx
Thanx for the information. I will get back to you once I have done with it
sandeep did you find the way , how to send sms using microsoft application if yes then plese send me at [email protected]
sandeep you got this ??
and also, I m using windows as web development environment, how can I run the php script you have given? Please give suggestions!
Thanks,
Sandeep
I need a script to send bulk sms thru way2sms with same msg to all.
thanks
You can use V2.0 of the class which supports passing a list of numbers to the send function as a an array. Although the v2.0 doesnt include way2sms as of now. Hope someone in here can help me migrate the old way2sms scripts to v2.0
can’t we use looping in way2sms to sending multiple SMS ?
admin..does this work internationally and unlimited?
i will need your help to run my website..would you be kind to contact me back.
thank you.
This does not work all over the world. It actually depends on the gateway. The 160by2 gateway supports the maximum number of countries like India, Singapore, Kuwait, UAE etc. You can contact me using the Contact page (link on the top of the page)
it seems that the advanced v 2 script doesn’t works on freesms8.com …
showing a error ” Logging in … Sending SMS … Error encountered : ”
But not the actual error …
kindly look into the matter…
it seems that the advanced v 2 script doesn’t works on freesms8.com …
showing a error ” Logging in … Sending SMS … Error encountered : ”
But not the actual error …
kindly look into the matter and please restore it soon……
I will look into the issue when I find some time
Hi,
Thanks for the code but Im gettin the following errors. I tried to clear them but wasn’t successful.
could you please help me with these errors?
Notice: Use of undefined constant “class – assumed ‘“class’ in C:\wamp\www\Assignment6\test\send_sms1.php on line 2
Notice: Use of undefined constant curl – assumed ‘curl’ in C:\wamp\www\Assignment6\test\send_sms1.php on line 2
Notice: Use of undefined constant php” – assumed ‘php”’ in C:\wamp\www\Assignment6\test\send_sms1.php on line 2
Warning: include_once(“classcurlphp”) [function.include-once]: failed to open stream: No such file or directory in C:\wamp\www\Assignment6\test\send_sms1.php on line 2
Warning: include_once() [function.include]: Failed opening ‘“classcurlphp”’ for inclusion (include_path=’.;C:\php5\pear’) in C:\wamp\www\Assignment6\test\send_sms1.php on line 2
Notice: Use of undefined constant “class – assumed ‘“class’ in C:\wamp\www\Assignment6\test\send_sms1.php on line 3
Notice: Use of undefined constant sms – assumed ‘sms’ in C:\wamp\www\Assignment6\test\send_sms1.php on line 3
Notice: Use of undefined constant php” – assumed ‘php”’ in C:\wamp\www\Assignment6\test\send_sms1.php on line 3
Warning: include_once(“classsmsphp”) [function.include-once]: failed to open stream: No such file or directory in C:\wamp\www\Assignment6\test\send_sms1.php on line 3
Warning: include_once() [function.include]: Failed opening ‘“classsmsphp”’ for inclusion (include_path=’.;C:\php5\pear’) in C:\wamp\www\Assignment6\test\send_sms1.php on line 3
Fatal error: Class ‘sms’ not found in C:\wamp\www\Assignment6\test\send_sms1.php on line 5
Looks like your php scripts are corrupted. Ensure that all the php files in the zip are extracted to the same directory.
Dear Kiran Saheb,
I was using your example.php script successfully from my website but I think my hosting people got suspicious and blamed me of overusing their server CPU at present my members are very less but with the time they will increase. I need another website and hosting service just for sending these free sms to my members who joins. Pls suggest me a reasonalble hosting service and that will simply allow me to send sms using your example.php without any danger of suspending my website. One more thing I want to ask you that if my hosting service is suspended will I be able to use the name of my website with other hosting party. How will I have control over my website name.
Thanks
Sandy
I use hostmonster.com/bluehost.com, they provide unlimited bandwidth for a very reasonable price. Around 3.5 K Rs per year.
You can use your domain name with any hosting company , this is applicable if you bought the domain name separately from the hosting, like from providers like godaddy.com. But if the domain name came free with the hosting, then you might need to request them to transfer the domain .. although I am not sure about their policies.
I have also heard that godaddy hosting is good.
Just try to avoid using Indian hosting companies as bandwidth in India is costlier compared to US.
tell me i want to get complete site like way2sms.com. i am ready to pay for it. from where to get it.
way2sms is not just a website. Its a combination of a web UI and a SMS gateway (offered by its parent company smscountry)
So if you are buying just the website it wont be enough. You will need to pay for every SMS being sent using the website.
Way2sms tries to cover up the SMS cost with the revenue from the ads. So if you are trying to do something similar, it might take some time for you to break-even as there wont be enough advertisers willing to pay unless the customer base is big enough.
Hope it makes sense..
Logging in … Sending SMS …
Fatal error: Call to undefined function json_decode() in /www/110mb.com/t/i———talacse/htdocs/sms/gateway_freesmsapi_com.php on line 41
Looks like your hosting server runs PHP4. json-decode function was introduced in PHP5.
please add freesms8.com also please at present its not working…….
thanks in advance…
I have added freesms8.com, but it has stopped working recently. I have posted an update about this. Read the update dated 17th Dec ’10 on the top of the page.
Hey..
Nowdays 160by2 is not working sometimes I think its because thier mobile version site is down and you seems to using m.160by2 in the code to login and post sms right?
Their website is still functional. So I belive it can be solved if you could use the website for posting the sms instead of m.160by2.com. The login is successful but the page m.160by2.com/SaveCompose.asp doesn’t exist and hence the sms is not getting send.
I’m getting this maybe because I have made CURLOPT_FOLLOWLOCATION, 0. Anyhow is there a solution for it?
You are right Afsal. But I have decided to stop development. Read the update dated 17th Dec ’10 on the top of this page.
Sir,
I want to use HTTP API for http://www.freesms8.com. When I use your code I got an error message as -
Logging in … Sending SMS … Error encountered : One or more parameters are missing
Please help to run it.
Thanks in Advance.
I wish I could fix the code, but please read the update dated 17th Dec ’10 on the top of this blog post.
Sorry for my previous post.
The error message is as follows
Logging in … Sending SMS … Error encountered :
great work sir.both 160by2.com and freesmsapi are working fine.but freesms8.com is not working.
The error message is as follows
Logging in … Sending SMS … Error encountered .
Please correct this problem and also add way2sms as it provides unlimited free sms.
Otherwise,Fantastic work sir.
Pls read the update dated 17th Dec ’10 on the top of this blog post.
I want to use http://www.freesms8.com for sending sms
but when I run PHP SMS API v2.0 I got the following error…
Logging in … Sending SMS … Error encountered :
Please response as soon as possible..