0

我想从我的网站发送短信。php 代码在本地主机上运行良好,但没有从 Web 服务器获得任何响应。我是否错过了在 Web 服务器中配置某些内容?请帮帮我..这是下面给出的代码...

<?php

$ch = curl_init("http://priority.muzztech.co.in:8080/sms?");
curl_setopt($ch, CURLOPT_POSTFIELDS,"username=username&password=password&type=0&dlr=1&destination=+91xxxxxxxxxx&source=XXXXXX&message=test");
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);

$contents = curl_exec ($ch);
curl_close ($ch);

Print($contents);

/*if(stristr($contents,"Message Submitted")){
$mstatus="SMS send Sucessfully ";}
else {
$mstatus="SMS send Failed";} 
*/

?>

将代码编辑为

<?php

$ch = curl_init("http://priority.muzztech.co.in:8080/sms?");

curl_setopt($ch, CURLOPT_POST, True);
curl_setopt($ch, CURLOPT_POSTFIELDS,"uusername=username&password=password&type=0&dlr=1&destination=+91xxxxxxxxxx&source=XXXXXX&message=test");
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);

$contents = curl_exec ($ch);

var_dump(curl_getinfo($ch));

curl_close ($ch);
Print($contents);
/*if(stristr($contents,"Message Submitted")){
$mstatus="SMS send Sucessfully ";}
else {
$mstatus="SMS send Failed";} 
*/

?>

显示的页面

<pre>array(20) { 
["url"]=> string(40) "http://priority.muzztech.co.in:8080/sms?" 
["content_type"]=> NULL 
["http_code"]=> int(0) 
["header_size"]=> int(0) 
["request_size"]=> int(0) 
["filetime"]=> int(-1) 
["ssl_verify_result"]=> int(0) 
["redirect_count"]=> int(0) ["total_time"]=> float(21.226878) 
["namelookup_time"]=> float(0.22723) 
["connect_time"]=> float(0) 
["pretransfer_time"]=> float(0) 
["size_upload"]=> float(0) 
["size_download"]=> float(0) 
["speed_download"]=> float(0) 
["speed_upload"]=> float(0)
["download_content_length"]=> float(-1)
["upload_content_length"]=> float(-1)
["starttransfer_time"]=> float(0) 
["redirect_time"]=> float(0) }</pre>
4

3 回答 3

0

我也遇到了同样的问题,并试图用一整天的时间来解决这个问题。在我的本地主机中一切都运行良好,但是当我将它放在 Web 服务器中时,这里没有任何工作。

我用上面的代码做了一点改动,现在它对我有用。我试图通过很多组合来解决这个问题。令人惊讶的是,我看到当我使用端口号 8080 时,这里没有任何工作。但是当我删除端口号并尝试再次发送我的短信时,它正在工作。我还从上面的代码中将 'uusername' 更改为 'username'。

最后我的代码是:

<?php

$ch = curl_init("http://priority.muzztech.co.in/sms?");

curl_setopt($ch, CURLOPT_POST, True);
curl_setopt($ch, CURLOPT_POSTFIELDS,"username=username&password=password&type=0&dlr=1&destination=8801XXXXXXXXX&source=XXXXXX&message=test");
//8801XXXXXXXXX mobile number format for Bangladesh
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);

$contents = curl_exec ($ch);

curl_close ($ch);

?>
于 2013-11-24T18:26:49.337 回答
0

在进行 CURL HTTP post 时需要在CURLOPT_POST, true前面指定CURLOPT_POSTFIELDS, ...,因为 CURL 的默认 http 方法是 GET。

于 2013-02-23T11:30:45.630 回答
0
**In my case below code worked successfully** 

$abc= 'http://bullet1.sdctechnologies.co.in:8080/api/mt/SendSMS?user='.$sms_username.'&password='.$sms_password.'&senderid='.$sms_sender_id.'&channel=Trans&DCS=0&flashsms=0&number='.$txt_mobile.'&text='.$message.'';

 $url = str_replace(" ","%20",$abc);
            $ch = curl_init();
            curl_setopt($ch,CURLOPT_URL,$url); 
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
            $response = curl_exec($ch);
            curl_close($ch);
于 2021-09-20T08:15:25.350 回答