以下php代码在网络服务器(即sms服务器所在的服务器)上运行良好
位置),但在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);
?>
代码有问题吗?互联网连接?
我们将不胜感激
答案 0 :(得分:0)
如果这在Web服务器上有效,但在您的本地主机上不起作用,则可能是CURL出现了防火墙问题。默认情况下,CURL使用端口1080。检查以查看该端口在您的本地主机上是否为opn或尝试通过
更改端口curl_setopt ($ch, CURLOPT_PORT , 8089);