短信api不在本地机器上工作,但如果放在托管服务器中工作?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (38)

下面的PHP代码可以很好地从Web服务器,即短信服务器

位于但不适用于具有xampp或wamp的本地计算机

实际的服务器是在godaddy

我错过了什么?

代码从表中检索连接详细信息

用户名,密码,msisdn,发件人,最终发送邮件时,

邮件被标记,因此不会再次发送

<?php

$id = 0;

$con=mysqli_connect("localhost","root","","afrcan_wp");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="SELECT id,message,username,password,MSISDN,sender,messagestatus FROM outgoingsms where messagestatus = 'not sent' LIMIT 1";

if ($result=mysqli_query($con,$sql))
  {
  // Fetch one and one row
  while ($row=mysqli_fetch_row($result))
    {

    $id=$row[0];    

    $text1=$row[1];

    $username=$row[2];

    $password=$row[3];

    $to=$row[4];

    $sender=$row[5];

    $messagestatus=$row[6];

 //$conn1=mysqli_connect("localhost","afrcan_wp","Sirhenry888","afrcan_wp");
$conn1 = new mysqli("localhost","root","","african_wp");
// Check connection
if ($conn1->connect_error) {
    die("Connection failed: " . $conn1->connect_error);
} 

$sql = "UPDATE outgoingsms SET messagestatus='sent' WHERE id=$id";

if ($conn1->query($sql) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $conn1->error;
}


$text = trim($text1);

$postUrl = "https://www.connectmedia.co.ke/user-board/?api";

$action="send";

$post = [
'action' => "$action",
'to' => array($to),
'username' => "$username",
'password' => "$password",
'sender' => "$sender",
'message' => urlencode("$text"),
];
$ch = curl_init($postUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$response = curl_exec($ch);
curl_close($ch);
echo "$response";

    //send messages
    }
  // Free result set
  mysqli_free_result($result);

 $conn1->close();

}

mysqli_close($con);

?>

这是代码的问题吗?, 网络连接 ?

任何援助将受到高度赞赏

提问于
用户回答回答于

如果这适用于Web服务器但在本地主机上不起作用,则可能是CURL存在防火墙问题。默认情况下,CURL使用端口1080。检查该端口是否在您的localhost上是opn,或尝试通过执行更改端口

curl_setopt ($ch, CURLOPT_PORT , 8089);

扫码关注云+社区

领取腾讯云代金券