Bulk SMS API

SMSCluster » Service » Bulk SMS API

Need help? Call us now on +91- 94068-11127

Send SMS Gateway API – PHP

This command can be used to send text messages to either individual numbers or entire contact groups.

Sample Request

                
  1. <?php
  2. include "getpost-lib.php";
  3. $name = $_REQUEST["name"];
  4. $message = $_REQUEST["message"];
  5. $mobileNumber=$_REQUEST["number"];
  6. $email=$_REQUEST["email"];
  7. $message="Hi ".$name." we received your request. from number is: ".$mobileNumber." and from email ".$email;
  8. $senderId="sender";
  9. $serverUrl="serverUrl";
  10. $authKey="yourAuthkey";
  11. $route="1";
  12. echo sendsmsGET($mobileNumber,$senderId,$route,$message,$serverUrl,$authKey);
  13. ?>
                    
  1. <?php
  2. include "getpost-lib.php";
  3. $name = $_REQUEST["name"];
  4. $message = $_REQUEST["message"];
  5. $mobileNumber=$_REQUEST["number"];
  6. $email=$_REQUEST["email"];
  7. $message="Hi ".$name." we received your request. from number is: ".$mobileNumber." and from email ".$email;
  8. $senderId="sender";
  9. $route="1";
  10. $serverUrl="serverUrl";
  11. $authKey="yourAuthkey";
  12. echo sendsmsPOST($mobileNumber,$senderId,$route,$message,$serverUrl,$authKey);
  13. ?>
                    
  1. <?php
  2. function sendsmsGET($mobileNumber,$senderId,$route,$message,$serverUrl,$authKey)
  3. {
  4. $getData = 'authkey=' .$authKey.'&mobileNos='.$mobileNumber.'&message='.urlencode($message).'&senderId='.$senderId.'&route='.$route;
  5. //API URL
  6. $url="http://".$serverUrl."/rest/services/sendSMS/sendGroupSms?AUTH_KEY=".$authKey."&"3.$getData;
  7. // init the resource
  8. $ch = curl_init();
  9. curl_setopt_array($ch, array(
  10. CURLOPT_URL => $url,
  11. CURLOPT_RETURNTRANSFER => true,
  12. CURLOPT_SSL_VERIFYHOST => 0,
  13. CURLOPT_SSL_VERIFYPEER => 0
  14. ));
  15. //get response
  16. $output = curl_exec($ch);
  17. //Print error if any
  18. if(curl_errno($ch))
  19. {
  20. echo 'error:' . curl_error($ch);
  21. }
  22. curl_close($ch);
  23. return $output;
  24. }
  25. function sendsmsPOST($mobileNumber,$senderId,$route,$message,$serverUrl,$authKey)
  26. {
  27. //Prepare you post parameters
  28. $postData = array(
  29. 'authkey' => $authKey,
  30. 'mobileNumbers' => $mobileNumber,
  31. "groupId" => "0",
  32. 'smsContent' => $message,
  33. 'senderId' => $senderId,
  34. 'route' => $route,
  35. "smsContentType" =>'english'
  36. );
  37. $data_json = json_encode($postData);
  38. $url="http://".$serverUrl."/rest/services/sendSMS/sendGroupSms?AUTH_KEY=".$authKey;
  39. // init the resource
  40. $ch = curl_init();
  41. curl_setopt_array($ch, array(
  42. CURLOPT_URL => $url,
  43. CURLOPT_HTTPHEADER => array('Content-Type: application/json','Content-Length: ' . strlen($data_json)),
  44. CURLOPT_RETURNTRANSFER => true,
  45. CURLOPT_POST => true,
  46. CURLOPT_POSTFIELDS => $data_json,
  47. CURLOPT_SSL_VERIFYHOST => 0,
  48. CURLOPT_SSL_VERIFYPEER => 0
  49. ));
  50. //get response
  51. $output = curl_exec($ch);
  52. //Print error if any
  53. if(curl_errno($ch))
  54. {
  55. echo 'error:' . curl_error($ch);
  56. }
  57. curl_close($ch);
  58. return $output;
  59. }
  60. ?>
                    
  1. <?php
  2. define("AUTH_KEY", "1b34cf67c6546ed7734c6aa568d45b0");
  3. function sendsms($mobileNumber,$senderId,$route,$message)
  4. //Your authentication key
  5. $authKey = AUTH_KEY;
  6. $route = "default";
  7. $getData = 'authkey=' .$authKey.'&mobiles='.$mobileNumber.'&message='.$message.'&sender='.$senderId.'&route='.$route;
  8. $url="http://msg.msgclub.net/rest/services/sendSMS/sendGroupSms"."?".$getData;
  9. // init the resource
  10. $ch = curl_init();
  11. curl_setopt_array($ch, array(
  12. CURLOPT_URL => $url,
  13. CURLOPT_RETURNTRANSFER => true,
  14. ));
  15. $output=curl_exec($ch);
  16. curl_close($ch);
  17. return $output;
  18. }
  19. <?>

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.

Parameters

sender If you have a promotional account, do not send this parameter. If you have a transactional account, use this field to specify the sender name for your message. Sender name must be 6 alpha characters and should be pre-approved by Textlocal. In the absence of approved sender names, use the default 'TXTLCL'
message The message content. This parameter should be no longer than 766 characters. See Helpful Information for message length details. The message also must be URL Encoded to support symbols like &.
Login Parameters (Additional Information)
username The email address used to log into Textlocal.
hash Your secure hash can be found within Messenger in the main navigation under "Help->All Documentation". Alternatively you can use the password parameter instead and use your Textlocal password in plain text.
Optional Parameters
apiKey This can be used instead of the username/hash/password. You can create them in your Messenger Control Panel (click here) for each application, and limit the usage of them by host IP Address.
numbers Comma-delimited list of mobile numbers in international format (i.e. 918123456789).
group_id This parameter can be used in place of the numbers parameter in order to send to an entire contact group. This parameter should contain the ID of the relevant group, which can found either within Messenger (in the "Reports" - "Advanced Reports" - "List of Group ID's" section) or by running the get_groups command. Additionally group 5 contains "contacts" and group 6 contains "opt-outs".
schedule_time This parameter can be used to specify a schedule date/time for your message, which should be provided in Unix timestamp format. Times should be provided in GMT.
receipt_url Use this field to specify an alternative URL to which the delivery receipt(s) will be sent. See handling receipts documentation.
custom This value will be set against the message batch and will passed back in the delivery receipts. This allows you to match delivery receipts to their corresponding messages.
optouts Can be set to true in order to check against your own opt-outs list and Textlocal's global opt-outs database. Your message will not be sent to numbers within these lists. If not provided defaults to false.
unicode Set this value to true to specify that your message body will contain unicode characters. See Encoding/Decoding Unicode Documentation
test Set this field to true to enable test mode, no messages will be sent and your credit balance will be unaffected. If not provided defaults to false
Note: While both numbers and group_id are optional parameters, one or the other must be included in the request for the message to be sent.

Errors

Error Codes Description
3001 * for Success
3002 * Invalid URL
3003 * Invalid User/Password
3004 * Invalid Message Type
3005 * Invalid Message
3006 * Invalid Destination
3007 * Invalid Source
3008 * Invalid DLR Field
3009 * Authentication Failed
3010 * Internal Error
3011 * Insufficient Balance
3012 * Responce Time Out
3013 * Invalid Request Content Type
3014 * Missing Mobile Number
3015 * SMs Content for Approval
3016 * Missing Required Parameter
3017 * FAIL
3018 * Expired Account
3019 * Null Pointer Exception code
3020 * Empty User Name
3021 * Empty Password
3022 * User Name not Available
3023 * Session Expired
3024 * Already Exist
3025 * Empty Group Name
3026 * Empty Contact Name
3027 * Empty Mobile Number
3028 * Empty Group Id
3029 * Empty City Name
3030 * Empty Occupation
3041 * Empty E-Mail Id
3042 * Group not Exist
3043 * Empty Message
3044 * Empty Route Id
3045 * Empty Sender Id
3047 * Empty Draft Id
3048 * Empty First Name
3049 * Empty Last Name
3050 * Empty Balance
3051 * Empty Role Id
3052 * For User Name Length
3053 * Empty Expiry Date/td>
3054 * Invalid Date
3055 * Empty Client Id
3056 * Invalid Status
3057 * Empty Country Name
3058 * Empty State Name
3059 * Session Expired
3060 * Empty Date
3061 * Access Denied
3062 * Empty Old Password
3063 * Password not Maching
3064 * Empty SMS
3065 * Empty Amount
3066 * Empty Address
3067 * Empty RequestId
3068 * Empty Group and MobileNo
3069 * Empty Description
3070 * Fail to Change RoleId
3071 * Empty CallerId
3072 * Empty File URL and Draft
3073 * Empty Duration
3074 * Invalid Request
3075 * Invalid Aoudio file
3076 * Missing Upload File

Warnings

Warning Codes
3 Invalid number.