A lot of times we come across a need to send sms from our website to customer, for that we need to purchase sms gateway. Almost all sms gateways have their documentation on how to use their gateway which at times are not meaningful or difficult to understand.
Also if in future you decide to change your gateway you will need to repeat the stuff. Reading the docs, following their steps and changing your code.
Rather, doing this hectic stuff you are better-off using the PHP cUrl library which is a very efficient and powerful one and allows you to connect and communicate to different servers.
Not just for sending sms, you can use it for different purposes whenever you want two different servers to communicate
For more information on cURL visit http://www.php.net//manual/en/book.curl.php
The below code connects to the SMS gateway and then sends the mess-age.
$url = "http://smsurl/sms1"; // URL of the SMS Gateway $curl_connection = curl_init($url); //Initialize curl handle curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); //Set the post variables like username , password , sms text etc. $result = curl_exec($curl_connection); //run the whole process and return the response curl_close($curl_connection); //close the curl handle
- In the above code first the connection to the SMS Gateway is made.
- Then the variables like username, password etc is passed.
- These parameters and url are given by the SMS Gateway Provider.
- The URL is then executed and finally the connection with the Gateway is closed.
At Taksa we have developed such applications that cater to various client needs. With Application Outsourcing on the rise, there is a need of getting more and more custom development on board.