Wednesday, December 7, 2011

Send sms using PHP


Hi friends, if you are in India and if you are developing software prototypes which has to send SMS alerts to various Indian mobile numbers, you needn’t spend a lot to buy SMS credits at the various sites. Over the last weekend, I spent some time hacking up a quick SOAP based web service which you can consume in your programs.
Please note that you need to create an account at www.way2sms.com before proceeding further.
How to Use – Method 1:
Currently the web service is active at http://www.aswinanand.com/sendsms.php. This accepts four parameters.
Parameter NameDescription
uidThis represents the 10 digit phone number with which you have to login at way2sms.
Note: This web service may not work if you try logging in with email address.
pwdYour way2sms password
phoneOne or more phone numbers to which SMS has to be sent. Phone numbers should be separated by semicolon (;). E.g. 9812345678;9933445566
msgMessage that has to be sent.
The URL – http://www.aswinanand.com/sendsms.php – can be invoked with the parameters as follows:
http://www.aswinanand.com/sendsms.php?uid=9933445566&pwd=password&phone=9812345678;9933445566&msg=Hello+World
You can also do a HTTP POST to the same URL to send the SMS. Here’s an example:
<form method=”post” action=”http://www.aswinanand.com/sendsms.php“>
<input type=”hidden” name=”uid” value=”9933445566″ />
<input type=”hidden” name=”pwd” value=”password” />
<input type=”hidden” name=”phone” value=”9812345678;9933445566″ />
<input type=”hidden” name=”msg” value=”Hello World” />
<input type=”submit” value=”Send SMS” />
</form>
How to Use – Method 2:
The functionality is also exposed as a SOAP (Simple Object Access Protocol) WSDL (Web Service Description Language). WSDL can be accessed athttp://www.aswinanand.com/sendsms.php?wsdl. To know more about how to use this WSDL in Microsoft Visual Studio, check out this article.
Deploying on your own Server:
To deploy this SMS script on your own server, first download the source code & follow the instructions:
  1. Let us assume that you wish to run the service at http://www.example.com/sms/sendsms.php. Here, http://www.example.com/ is your domain, “sms” is the folder and “sendsms.php” is the PHP script in that folder.
  2. Hence, using FTP or SSH, login to your domain hosting space and create a folder named “sms”.
  3. Extract the source code to the “sms” folder. If you don’t want to expose a SOAP WSDL, feel free to skip to step 6.
  4. Since the SMS source code supports SOAP, you have to download the ‘nusoap’ library. Then extract the ‘nusoap’ library to the same “sms” folder.
  5. Once everything is extracted, the folder structure should be:
    • example.com
      • sms/
        • sendsms.php
        • htmlparser.inc (optional)
        • nusoap/
          • class.nusoap_base.php
          • class.soap_transport_http.php
          • class.wsdlcache.php
          • class.soap_fault.php
          • class.soap_val.php
          • class.xmlschema.php
          • class.soap_parser.php
          • class.soapclient.php
          • class.soap_server.php
          • class.wsdl.php
          • nusoapmime.php
          • nusoap.php
  6. Try accessing your web service at http://www.example.com/sms/sendsms.php now.
You can use the same parameters described above for sendsms.php and access it as:
http://www.example.com/sms/sendsms.php?uid=9933445566&pwd=password&phone=9812345678;9933445566&msg=Hello+World
or you can also do a HTTP POST as indicated above.
Download:
Download the PHP source code here.
Other Languages:
Currently this SMS web service is available in the following programming languages:

Bind Some Event to Element and trigger that function when click the element

Scenario: Suppose if we used same click event function in various web pages. if you want do some logic some page button for that need to re...