【问题标题】:Simple php code for sending Infobip sms to a phone用于向手机发送 Infobip 短信的简单 php 代码
【发布时间】:2015-05-23 21:09:59
【问题描述】:
我需要帮助才能从网站上的表单发送短信。
我试过下面的代码没有成功。
<?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';
}
?>
【问题讨论】:
标签:
php
infobip
infobip-api
【解决方案1】:
您应该添加一些逻辑来调用实际的 $posturl。
你可以检查cUrl,或者做一个简单的file_get_contents($posturl);
【解决方案2】:
<?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;
}
?>
它将根据返回响应行将响应作为数组返回。
【解决方案3】:
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); ?>