3

I have a code below. When I submit the form AJAX I got the SMS, but confirmation message not displaying on user front end. Also, how can I get the cURL response result. I use var_dump($response), but it displays just bool(true) message sent or not sent. I follow some instruction in this PDF viewer demo

<?php   
 // send_sms.php     page

// Infobip's POST URL send sms
$applicantName = "test"; //name
$contactNo = "00"; // number

$postUrl = "http://api2.infobip.com/api/sendsms/xml"; 
$from = 'test';
$message = "Dear".$applicantName.",Thank you ...";  // message
$to = '21'.$contactNo;
// XML-formatted data
$xmlString =
"<SMS>
<authentification>
<username></username>
<password></password>
</authentification>
<message>
<sender>".$from."</sender>
<text>".$message."</text>
</message>
<recipients>
<gsm>".$to."</gsm>
</recipients>
</SMS>";
// previously formatted XML data becomes value of "XML" POST variable
$fields = "XML=" . urlencode($xmlString);
// in this example, POST request was made using PHP's CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postUrl);
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_HEADER, TRUE); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
// response of the POST request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
curl_close($ch); 
// end send sms process
if ($httpCode >= 200 && $httpCode < 300) {
echo "success";
}else{
echo "failed";
}

?>
msmolcic
  • 6,407
  • 8
  • 32
  • 56
Riyadh Ahmed
  • 1,139
  • 1
  • 9
  • 17

0 Answers0