0

I try to use the below example of sending sms by Textlocal.com:

$apiKey = urlencode('Your apiKey');

$numbers = array('123456789');
$sender = urlencode('TXTLCL');
$message = rawurlencode('This is your message');

$numbers = implode(',', $numbers);

$data = array('apikey' => $apiKey, 'numbers' => $numbers, "sender" => $sender, "message" => $message);

$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;

I always receive the error:

{"errors":[{"code":3,"message":"Invalid login details"}],"status":"failure"}

Link to the documentation: https://api.textlocal.in/docs/sendsms

Does anyone have a solution to the problem ?

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • Cab you provide a link to the documentation of this service, where it tells you how to authenticate a request – ADyson Jun 08 '22 at 07:59
  • Of course, link to the documentation: https://api.textlocal.in/docs/sendsms – Chris C0der Jun 08 '22 at 08:08
  • Thanks. Any reason you didn't use their ready-made PHP class as shown at https://api.textlocal.in/docs/phpclass ? – ADyson Jun 08 '22 at 08:13
  • Anyway the error message says the login failed...so presumably your API key is incorrect or has been disabled. Either that or it got mangled by being URL-encoded more than once or something (depending on if there any characters in it which are significant in a URL). – ADyson Jun 08 '22 at 08:15
  • Pretty sure cURL applies URL encoding itself, when an array gets passed for CURLOPT_POSTFIELDS. So I think this code will encode some of the values twice ...? – CBroe Jun 08 '22 at 08:16
  • Clearly a case for the support of the vendor... – Honk der Hase Jun 08 '22 at 08:24
  • I fixed the issue. I changed the url (in curl_init function) to 'https://api.txtlocal.com/send/' and works! :) – Chris C0der Jun 08 '22 at 14:33

0 Answers0