I am using Text Local SMS API and echoing out the response in PHP, although the "response" says success but the delivery status in the report panel of the text local api shows that the status is invalid. Here is my code: I have hidden the api, sender and phone number here.
$OTP = rand(1000,9999);
$apiKey = urlencode('My API');
// Message details
$var= $OTP;
//10 digit phone number with country code 91
$numbers = array(911234567890);
$sender = urlencode('XXXXXX');
$message = rawurlencode("Dear User, your OTP login is ".$var." . This OTP is valid only for 24 hours.");
$numbers = implode(',', $numbers);
// Prepare data for POST request
$data = array('apikey' => $apiKey, 'numbers' => $numbers, "sender" => $sender, "message" => $message);
// Send the POST request with cURL
$ch = curl_init('https://api.textlocal.in/send/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
The output I get after execution is:
{"balance":988,"batch_id":1834685178,"cost":1,"num_messages":1,"message":{"num_parts":1,"sender":"xxxxxx","content":"Dear User, your OTP login is 8836 . This OTP is valid only for 24 hours."},"receipt_url":"","custom":"","messages":[{"id":"12565543282","recipient":911234567890}],"status":"success"}
I tried using the message id to check the delivery status. Here is the code.
// Account details
$apiKey = urlencode('My API');
// Message Details
$message_id = '12565543282';
// Prepare data for POST request
$data = array('apikey' => $apiKey, 'message_id' => $message_id);
// Send the POST request with cURL
$ch = curl_init('https://api.textlocal.in/status_message/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// Process your response here
echo $response;
Below is the response of the delivery status. The status "I" means invalid delivery status as per documentation of Text Local.
{"message":{"id":12565543282,"recipient":911234567890,"type":"sms","status":"I","date":"2021-06-27 11:00:45"},"status":"success"}
I have also tried using username and hash instead of the api key but still the results are same. I also tried the same scripts in both localhost and in server but the results are still the same. Can anybody help??