0

I have a problem using Infobip sms gateway. I have no idea about below code when i execute this code there is a error called no HttpRequest class found. Any one please help me.

<?php

$request = new HttpRequest();
$request->setUrl('https://api.infobip.com/sms/1/text/single');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'accept' => 'application/json',
  'content-type' => 'application/json',
  'authorization' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
));

$request->setBody('{  
   "from":"InfoSMS",
   "to":"41793026727",
   "text":"Test SMS."
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
msmolcic
  • 6,407
  • 8
  • 32
  • 56
Dim236
  • 31
  • 1
  • 1
  • 3
  • You can remove javascript and xml tags. Could you please include your environment info, php version, [pecl http](https://pecl.php.net/package/pecl_http) version, and exact error message you get (including the invocation info)? – maricn Jul 23 '15 at 10:15
  • Please tell me how to execute this please – Dim236 Jul 23 '15 at 10:22

1 Answers1

0

You can use below..It's working for me.

    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://lzz25w.api.infobip.com/sms/2/text/advanced',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS =>'{"messages":[{"from":"$from","destinations":[{"to":"'.$to.'"}],"text":"'.$message.'"}]}',
        CURLOPT_HTTPHEADER => array(
            'Authorization: {authorization}',
            'Content-Type: application/json',
            'Accept: application/json'
        ),
    ));

    $response = curl_exec($curl);

    curl_close($curl);
   // echo $response;
Neeraj Prajapati
  • 541
  • 5
  • 24