3

我在下面有一个代码。当我提交表单 AJAX 时,我收到了 SMS,但确认消息未显示在用户前端。另外,如何获得 cURL 响应结果。我使用var_dump($response),但它只显示已bool(true)发送或未发送的消息。我遵循此 PDF 查看器演示中的一些说明

<?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";
}

?>
4

0 回答 0