How to USE API to send SMS by PHP

These days bulk SMS feature is used for the various purpose in the web application. For example user authentication, OTP verification, sending the notification to users. To send bulk SMS from PHP script you need to select a best and cheapest SMS gateway provider that suitable for your requirement. Once the bulk SMS gateway and plan selection are completed, now it’s time to integrate SMS gateway in PHP script.

In this tutorial, we will show you how to integrate SMS gateway API in PHP. SMS gateway integration process is very simple and less time required. Using our example code you can easily send SMS from your website using SMS gateway API and PHP.

Usually, the SMS provider provides 3 types of plan, One-way messages, Two-way messages, and Both-ways messages. One-way messaging allow you to send SMS to the customers, but Two-way messaging allow not only the send SMS but also receive a reply from the customer.

Generally, SMS gateway provides a callback URL for passing some parameters, like API Key, sender number, receiver number, message content, etc. The parameters can differ for the different SMS gateway, based on that you need to change or add parameters in the following script.


//request parameters array

$Key="API Key";
$senderId="Sender ID";
$finalmessage="Your Msg";

$postData = array(
'username' => $username,
'api_key' => $Key,
'sender' => $senderId,
'to' => $tophonenumber,
'message' => $finalmessage,
'msgtype' => 5,
'dlr' => 0,

$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,


curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

$output = curl_exec($ch);

if (curl_errno($ch)) {

$output = curl_error($ch);


//or use this code

$Key="API Key";
$senderId="Sender ID";
$finalmessage=urlencode("Your Msg");

$output1= $parse_url[0];


Through our API portal we can guide you on how to integrate with the SMS API from PHP. Our most popular API is the HTTP to SMS API.  In few lines of code, your PHP application can send, receive, and reply text messages

Add Comment

4 + 16 =

error: Content is protected !!