256 thoughts on “PHP class to send SMS using free SMS gateways

  1. harmeet

    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

    Reply
  2. Salan Khalkho

    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

    Reply
    1. admin Post author

      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.

      Reply
  3. rajkumar

    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

    Reply
    1. admin Post author

      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.

      Reply
  4. Sumit Joshi

    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.

    Reply
    1. admin Post author

      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

      Reply
  5. mythili

    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 :

    Reply
  6. Sanjay

    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

    Reply
  7. Afsal

    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.. :)

    Reply
    1. admin Post author

      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.

      Reply
    1. Saswata

      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 :

      Reply
  8. R Goyal

    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

    Reply
  9. admin Post author

    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.
    }

    Reply
  10. Dnz

    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…

    Reply
  11. harmeet

    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

    Reply
  12. Aishwin

    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]

    Reply
    1. admin Post author

      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 ;)

      Reply
      1. mark

        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

        Reply
  13. rahool

    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 :

    Reply
    1. admin Post author

      Can you verify whether you require a proxy to connect to the internet. Looks like PHP is not able to access their server.

      Reply
          1. rahool

            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 :

          2. rahool

            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 :)

          3. admin Post author

            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.

    1. admin Post author

      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 ? )

      Reply
  14. Sandy

    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

    Reply
    1. admin Post author

      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.

      Reply
  15. Sandy

    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

    Reply
  16. 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

    Reply
    1. admin Post author

      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']);

      Reply
  17. Sandy

    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 :

    Reply
    1. admin Post author

      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.

      Reply
        1. admin Post author

          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

          Reply
    1. admin Post author

      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

      Reply
    1. admin Post author

      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)

      Reply
  18. Dev

    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…

    Reply
  19. Dev

    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……

    Reply
  20. Naveen

    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

    Reply
    1. admin Post author

      Looks like your php scripts are corrupted. Ensure that all the php files in the zip are extracted to the same directory.

      Reply
  21. Sandy

    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

    Reply
    1. admin Post author

      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.

      Reply
    1. admin Post author

      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..

      Reply
  22. hillol

    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

    Reply
    1. admin Post author

      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.

      Reply
  23. Afsal

    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?

    Reply
    1. admin Post author

      You are right Afsal. But I have decided to stop development. Read the update dated 17th Dec ’10 on the top of this page.

      Reply
  24. Padhu

    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.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>