Send SMS Gateway API – PHP
This command can be used to send text messages to either individual numbers or entire contact groups.
Sample Request
- <?php
- include "getpost-lib.php";
- $name = $_REQUEST["name"];
- $message = $_REQUEST["message"];
- $mobileNumber=$_REQUEST["number"];
- $email=$_REQUEST["email"];
- $message="Hi ".$name." we received your request. from number is: ".$mobileNumber." and from email ".$email;
- $senderId="sender";
- $serverUrl="serverUrl";
- $authKey="yourAuthkey";
- $route="1";
- echo sendsmsGET($mobileNumber,$senderId,$route,$message,$serverUrl,$authKey);
- ?>
- <?php
- include "getpost-lib.php";
- $name = $_REQUEST["name"];
- $message = $_REQUEST["message"];
- $mobileNumber=$_REQUEST["number"];
- $email=$_REQUEST["email"];
- $message="Hi ".$name." we received your request. from number is: ".$mobileNumber." and from email ".$email;
- $senderId="sender";
- $route="1";
- $serverUrl="serverUrl";
- $authKey="yourAuthkey";
- echo sendsmsPOST($mobileNumber,$senderId,$route,$message,$serverUrl,$authKey);
- ?>
- <?php
- function sendsmsGET($mobileNumber,$senderId,$route,$message,$serverUrl,$authKey)
- {
- $getData = 'authkey=' .$authKey.'&mobileNos='.$mobileNumber.'&message='.urlencode($message).'&senderId='.$senderId.'&route='.$route;
- //API URL
- $url="http://".$serverUrl."/rest/services/sendSMS/sendGroupSms?AUTH_KEY=".$authKey."&"3.$getData;
- // init the resource
- $ch = curl_init();
- curl_setopt_array($ch, array(
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_SSL_VERIFYHOST => 0,
- 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);
- return $output;
- }
- function sendsmsPOST($mobileNumber,$senderId,$route,$message,$serverUrl,$authKey)
- {
- //Prepare you post parameters
- $postData = array(
- 'authkey' => $authKey,
- 'mobileNumbers' => $mobileNumber,
- "groupId" => "0",
- 'smsContent' => $message,
- 'senderId' => $senderId,
- 'route' => $route,
- "smsContentType" =>'english'
- );
- $data_json = json_encode($postData);
- $url="http://".$serverUrl."/rest/services/sendSMS/sendGroupSms?AUTH_KEY=".$authKey;
- // init the resource
- $ch = curl_init();
- curl_setopt_array($ch, array(
- CURLOPT_URL => $url,
- CURLOPT_HTTPHEADER => array('Content-Type: application/json','Content-Length: ' . strlen($data_json)),
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => $data_json,
- CURLOPT_SSL_VERIFYHOST => 0,
- 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);
- return $output;
- }
- ?>
- <?php
- define("AUTH_KEY", "1b34cf67c6546ed7734c6aa568d45b0");
- function sendsms($mobileNumber,$senderId,$route,$message)
- //Your authentication key
- $authKey = AUTH_KEY;
- $route = "default";
- $getData = 'authkey=' .$authKey.'&mobiles='.$mobileNumber.'&message='.$message.'&sender='.$senderId.'&route='.$route;
- $url="http://msg.msgclub.net/rest/services/sendSMS/sendGroupSms"."?".$getData;
- // init the resource
- $ch = curl_init();
- curl_setopt_array($ch, array(
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- ));
- $output=curl_exec($ch);
- curl_close($ch);
- return $output;
- }
- <?>
Caution: Some users opt to place their request inside a code loop, while testing we highly recommend setting the test parameter to true , as occasionally an infinite loop can occur and users can consume all their credits very quickly.