下面的php代码在web服务器(即sms服务器所在的位置)上运行良好,但在具有 xampp
或者 wamp
.
实际服务器在godaddy中
我错过了什么?
代码从一个表中检索连接详细信息,该表包括:username、password、msisdn和sender。当消息最终被发送时,消息将被标记,以便不再发送。
<?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);
?>
是代码问题吗?互联网连接?
如有任何帮助,我们将不胜感激
1条答案
按热度按时间g6ll5ycj1#
如果这在web服务器上工作,但在本地主机上不工作,那么可能是curl有防火墙问题。默认情况下,curl使用端口1080。检查该端口在本地主机上是否为opn,或者尝试通过执行