我的代码如下。当我提交表单AJAX时,我收到了短信,但确认消息没有显示在用户前端。另外,我如何获得cURL响应结果。我使用var_dump($response)
,但它只显示发送或未发送的bool(true)
消息。我按照PDF查看器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";
}
?>