短信网关问题PHP
问题描述:
我整合短信网关的第一次。当有人向网站付款时,我想发送短信。我使用下面的代码:短信网关问题PHP
<?php
$pay="1000";
$msg="Arivind";
echo $url="http://yourdomainname.com/api/swsend.asp?username=xxxxxx&password=xxxxxx&sender=SENDERID&sendto=91XXXXXXXXX&message=Dear'$msg' Thanks for making payment of Rs '$pay'";
$c=curl_init();
curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
curl_setopt($c,CURLOPT_URL,$url);
$contents=curl_exec($c);
curl_close($c);
echo "SMS Successfully sent";
?>
现在,如果我在邮件的正文使用变量,则不会发送消息,但如果我使用静态消息的消息是越来越传递到数目。 静态信息犯规解决我的目的,我需要的信息被发送到不同的人,变量即使用$味精会的人&从数据库中获取不同的名称。
亲切SUGGEST。
答
您还可以使用http_build_query到您的变量转换成格式良好的URL。单引号之间
http://www.tutorialspoint.com/php_mysql_online.php?PID=0Bw_CjBb95KQMWFpZLVJGLWZQYWM
<?php
$fname = 'Matthew';
$lname = 'Douglas';
$amount = 1000;
$message = "Thanks for your payment of Rs {$amount}.";
$urlComponents = array(
'firstName' => $fname,
'lastName' => $lname,
'message' => $message
);
$url = 'http://yourdomainname.com/api/swsend.asp?';
echo $url . http_build_query($urlComponents);
?>
答
使用变量'不将其转换成动态值。同时它能够更好地在简单的PHP函数RESTAPI:
function CURLcall($number, $message_body){
$api_params = "swsend.asp?username=xxxxxx&password=xxxxxx&sender=SENDERID&sendto=91XXXXXXXXX&message=$message_body";
$smsGatewayUrl = "echo $url="http://yourdomainname.com/api/";
$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);
}
}
致电上述功能:
$message_body = urlencode("Dear $msg Thanks for making payment of Rs $pay");
CURLcall('918954xxxxx',$message_body);
请注意:用urlencode是有用的,以避免在GET方法的错误,因为它转换空间为编码格式http://php.net/manual/en/function.urlencode.php
您使用urlencode php函数窗体消息,然后尝试发送 –