<?php
$username = 'XXXXXXXXXXX'; //bulksms username
$password = 'XXXXXXXXXXX'; //bulksms password
$mobile = '919762681119'; //Receiver's country code+number
$sms = "The message you want to send " ; //Double quotes are good for new line characters e.g. \n
$sms = urlencode($sms); //Very Important Otherwise spaces shall not be parsed correctly
$url = "https://bulksms.vsms.net/eapi/submission/send_sms/2/2.0?username=$username&password=$password&message=$sms&msisdn=$mobile";
$xml = file_get_contents($url);
echo $xml;
?>
它应该有所帮助 .
0
在简单的PHP函数(使用CURL)中调用短信RestApi来发送短信:
function CURLsendsms($number, $message_body){
$textmessage = urlencode($message_body);
$api_params = $api_element.'?apikey='.$apikey.'&sender='.$sender.'&to='.$number.'&message='.$textmessage;
$smsGatewayUrl = "http://springedge.com";
$smsgatewaydata = $smsGatewayUrl.$api_params;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_URL, smsgatewaydata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
// Use file get contents when CURL is not installed on server.
if(!$output){
$output = file_get_contents($smsgatewaydata);
}
}
<?php // sms
$user = "YOUR-USERNAME";
$pass = "YOUR-PASSWORD";
$mob = "919762681119,919762681118"; // Can come from a database
$msg = "Hello";
$url = "http://bulksms.megawebsource.com/sendsms.jsp?user=$user&password=$pass&mobiles=$mob&sms=$msg&senderid=NOTICE";
$xml = file_get_contents($url);
// Process XML if you need to
?>
5 回答
我遇到了同样的问题 . 可能错误在于您的API或消息结构 . 使用此改进的API:
它应该有所帮助 .
在简单的PHP函数(使用CURL)中调用短信RestApi来发送短信:
你也可以使用php类发送短信http://www.phpclasses.org/package/9522-PHP-Send-SMS-messages-with-Spring-Edge-API.html
上面有两个文件:
sendsms.php - 用于调用sms网关restAPI的类文件
test.php - 测试短信功能的示例文件 .
此类使用spring edge sms网关提供程序API,您可以根据需要为任何其他sms提供程序自定义RestAPI url和params .
您需要注册并可能需要付费 . PHP代码非常简单: -
通常可以用逗号分隔多个数字 .
我使用此代码发送短信 . 但是,请确保号码应为12位数,包括分机号码 . 例如:918080808080 . 接受用户的10位数字 . 在其上附加分机号码(91) . 还有一件事,有时会发生什么,消息不会转到那个数字 . 原因是他们的手机上的DNA(不允许)服务激活 . 如果在他们的SIM上激活DNA . 然后,这条短信不会GO .
为什么遭受丑陋和有限的网址?您可以使用现代且方便的our JSON REST API . 由于您已经通过curl library使用了http请求,因此使用我们为批量短信请求提供的两个选项之一是没有问题的(例如,参见this answer):
完整表格
当您描述要发送的每条消息时,所有遗漏的内容都将从模板中获取:
POST /sms/v1/{subAccountId}/many
紧凑形式
当您只列举电话号码时,其他所有内容都来自模板:
POST /sms/v1/{subAccountId}/many/compact
查看此tutorial以更顺利地深入了解API .