0

I have tried below code from here but there is a error called no HttpRequest class found. I am using php version 5.6.8(xampp v3.2.1). 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 sfdsdf=='  // name&password
));

$request->setBody('{  
   "from":"test",  //from
   "to":"000", // number
   "text":your verification code is = 000."
}');

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

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
msmolcic
  • 6,407
  • 8
  • 32
  • 56
Riyadh Ahmed
  • 1,139
  • 1
  • 9
  • 17

3 Answers3

0
$mob_no="mobile number";
$msg="Your message";
$sender_id='your sender id eg:VJPOTPYTL';
$str = trim(str_replace(' ', '%20', $msg));

$url="http://dnd.9starabs.com/app/smsapi/index.php?key=55942cc305ef6&type=text&contacts=".$mob_no."&senderid=".$sender_id."&msg=".$str."";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_exec($ch);
curl_close($ch);
Bowdzone
  • 3,827
  • 11
  • 39
  • 52
0

Since you are using php 5.4 or above, there does not seem to be a php_http.dll file to include in your extensions library (Unless someone can find one that I missed??).

The only one that I could find generated errors on starting up the Apache server after updating the php.ini configuration file to include the extension.

Check this link. Save it.
Then try this program:

include_once('HttpRequest.php'); //where HttpRequest.php is the saved file
$url= 'http://www.google.com/';
$r = new HttpRequest($url, "POST");
var_dump($r->send());  

If it doesn't work, then you might need to compile HTTP package yourself. You can find more here.

Ajay Kulkarni
  • 2,900
  • 13
  • 48
  • 97
  • I have tried this HttpRequest class before but it generated some error like..// Warning: Missing argument 1 for HttpRequest::__construct(), called in C:\xampp\htdocs\Training\sms\smsinfo.php on line 3 and defined in C:\xampp\htdocs\Training\sms\HttpRequest.php on line 26 Notice: Undefined variable: url in C:\xampp\htdocs\Training\sms\HttpRequest.php on line 28 Notice: Undefined index: host in C:\xampp\htdocs\Training\sms\HttpRequest.php on line 33 ... and sorry for this .i am new in stackoverflow and also this subject . – Riyadh Ahmed Dec 02 '15 at 09:55
0

Solution is to install PECL php extension. Answer was given several times on stack overflow, like on this thread:

"PHP Fatal error: Class 'HttpRequest' not found"

You can send SMS over web app using CURL instead of PECL. It is well explained and described on Infobip's blog. I recommend to give it a try:

http://www.infobip.com/blog/step-by-step-php-tutorial/

Community
  • 1
  • 1
Mosquito
  • 1
  • 1