我需要帮助从一个网站上的表单发送短信。
我已经尝试了下面的代码,但没有成功。
<?php
$username = '';
$password = '';
$from = $_POST['from'];
$to = $_POST['to'];
$message = $_POST['message'];
$text = urlencode($message);
//Send sms
private function sendSms(){
$posturl='http://api.infobip.com/api/v3/sendsms/plain?user=$username&password=$password&sender=$from&SMSText=$text&GSM=$to';
}
?>
您应该添加一些逻辑来调用实际的$posturl。
您可以检查cUrl,或者执行简单的file_get_contents($posturl);
<?php
$username = '';
$password = '';
$from = $_POST['from'];
$to = $_POST['to'];
$message = $_POST['message'];
$text = urlencode($message);
//Send sms
private function sendSms(){
$posturl=file('http://api.infobip.com/api/v3/sendsms/plain?user=$username&password=$password&sender=$from&SMSText=$text&GSM=$to');
return $posturl;
}
?>
它将根据返回的响应行返回响应作为数组。
Infobip API PHP教程
这是一个使用curl的示例代码:)http://api.infobip.com/api/sendsms/xml"; $xmlString = " Your infobip username infobip password title Your message here Phone number here "; $fields = "XML=" . urlencode($xmlString); $ch = curl_init($postUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); $response = curl_exec($ch); curl_close($ch); ?>