How to develop text SMS sending API script using PHP?

SMS  send  on  mobile  using  sms  API  in PHP

This article based on how to send sms on mobile using PHP.  Short Message Service (SMS) is text
Messaging   service by using mobile and web communication between clients and users.  SMS is mostly  used   application. The sms send using  sms  API  is very easy and send sms quickly.  API's are the most powerful  and reliable way to communicate between two servers.  Send  sms using  API  is  very secure. Using API we are send thousand sms same time. The example  below using API in php.  



message.php
                                  
// Your authentication key
$authKey = "7280A1SXJMbLr54d5d469";

// Multiple mobiles numbers separated by comma
$mobileNumber  =  S_POST[‘mobile’];

// Sender ID,While using route4 sender id should be 6 characters long.
$senderId = "ABCDEF";

// Your message to send, Add URL encoding here.
$message =  S_POST[‘message’];

// Define route
$route = "default";

// Prepare you post parameters
$postData = array(
    'authkey' => $authKey,
    'mobiles' => $mobileNumber,
    'message' => $message,
    'sender' => $senderId,
    'route' => $route
);

// API URL
$url="http://sms-api-website-url-for-request.com/sendhttp.php";

// init the resource
$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $postData
    //,CURLOPT_FOLLOWLOCATION => true
));

// Ignore SSL certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);


// get response
$output = curl_exec($ch);

// Print error if any
if(curl_errno($ch))
{
    echo 'error:' . curl_error($ch);
}

curl_close($ch);

echo $output;

?>
In the above example authentication key is used for login authority in API. Authentication key is unique for every user.  Authentication key is alphanumeric data type. In the mobile parameters we use  mobile number. The multiple  mobile numbers should be separated by comma (,).   In the message parameter we declare our text message. We can send sms on in different languages (such as english,  hindi,  Punjabi  etc.) by using unicode.  Sender ID parameter is show to receiver  will see this as sender's ID.  We are used in  sender ID  six variable character. If your SMS API operator support multiple roots then give one root  name (eg route=1 for  promotional messages and route=4 for transactional SMS).


Example:

form.html
<html>
     <body>
         <form method  = "post"  action = "message.php">
             <table>
          <tr>
                  <td>Mobile</td>
                    <td><input type = "text"  name = "mobile"></td>
                </tr>

               <tr>
                  <td>Message</td>
                    <td><input type = "textarea"  name = "message"></td>
                </tr>
          <tr>
                 <td><input type = "submit"  name = "submit"  value  =  "Submit"></td>
                 </tr>
             </table>
          </form>
       </body>
     </html>

The  example  below contains an HTML form with two input fields and a submit button.First text field is Mobile  field,   Second  message field  declare in the form.  When user fill the text field in  form click on submit button  the data will be send to PHP file .

The URL will look like this:

http://www.your-domain-name.com/message.php

The out will be  show in alphanumeric 24 character like  2548456a582s250001234879. If message not send successfully  you will get the  error message .



Students Tech Life