08 June 2011

How to send sms to mobile using PHP?

Few months ago, I had to add SMS sending facility in a website, for that we buy an SMS API from a company, now after buying SMS API, I had faced problem in how to integrate their API with PHP
I searched a lot on Google about it because the documentation provided by them was not much helpful ,so after long hours of searching on Google, finally I managed to find some clue, I found we can use curl .It is a very impressive library that allows you to connect and communicate to many different types of servers..

This code opens up a connection with the gateway, sends the SMS message(s) 

//this is the url of the gateway's interface
$url = "http://bulkpush.mytoday.com/BulkSms/SingleMsgApi";
//initialize curl handle
$curl_connection = curl_init($url);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); //set the POST variables
$result = curl_exec($curl_connection); //run the whole process and return the response
curl_close($curl_connection);  //close the curl handle                         

  • First of all, we initialize a new CURL session.
  • Then you have to pass all the variable ( such as username, password ,feedid or other things that you can read from documentation provided by your sms provider) to url.
  • Finally we execute the call and then close the handle.

So ,with this I will finish my tutorial on this ,if still have any query ,then feel free to ask