Thursday, 15 August 2013

How to send SMS using PHP

How can I send SMS using PHP?
Actually this is easy process but for this you have to purchase an API to send SMS. But I have found a solution to show your project temporarily. I have an API that provides a free trial and allows to send 5 free SMS that is sufficient to show the project.

To integrate this you have to follow the following steps :

  1) Go to site, on this site click on free trial as follow :

2) You will get a simple form, fill that form and after submission you will get a mail which will contain username and password.
   3) Now download the sms api from Here

   4) Place this file into your project folder

   5)  Now put the following code in the file and send SMS :
   <form method=post action='srisms.php'>
   <table border=0>
      <td>Recipient no:</td>
      <td><input type='text' name='recipient'></td>
      <td><textarea rows=4 cols=40 name='message' maxlength="140"></textarea></td>
      <td> </td>
      <td><input type=submit name=submit value=Send></td>
        $Mobile = "+91 Yourmobile No";
        // Declare variables.
        $Username = "";  //your username of vianetsms
        $Password = ""; //your password
        $MsgSender = $Mobile;
        $DestinationAddress = "+91".$_POST['recipient'];
        $Message = $_POST['message'];
        // Create ViaNettSMS object with params $Username and $Password
        $ViaNettSMS = new ViaNettSMS($Username, $Password);
            // Send SMS through the HTTP API
            $Result = $ViaNettSMS->SendSMS($MsgSender, $DestinationAddress, $Message);
            if ($Result->Success == true)
             echo  $Message = "Message successfully sent!";
     echo $Message = "Error occured while sending SMS<br />Errorcode: " . $Result->ErrorCode . "<br />Errormessage: " . $Result->ErrorMessage;
        catch (Exception $e)
            //Error occured while connecting to server.
            $Message = $e->getMessage();

No comments:

Post a Comment