我需要协助从网站上的表单发送短信 我尝试过以下代码但没有成功。
<?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';
}
?>
答案 0 :(得分:0)
你应该添加一些逻辑来调用实际的$ posturl。
你可以查看cUrl,或者做一个简单的file_get_contents($ posturl);
答案 1 :(得分:0)
<?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;
}
?>
它将根据返回响应行将响应作为数组返回。
答案 2 :(得分:0)
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); ?>