我正在使用 XAMPP,我想从数据库表中选择一个随机记录并通过电子邮件发送。我正在使用测试邮件服务器工具,但收到下一个错误:
警告:mail():第 24 行 C:\xampp\htdocs\dailyapp\sender2.php 中的错误消息返回路径 糟糕!出了点问题,我们无法发送您的消息。
这里可能发生什么?任何想法?
PHP代码:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "dapp";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$recipient = "mdrr5545@gmail.com";
$sql = "SELECT * FROM my_messages ORDER BY RAND() LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
($row = $result->fetch_assoc());
$subject = $row["subject"];
$message = $row["message"];
if (mail($recipient, $subject, $message)) {
http_response_code(200);
echo "All good";
}
else {
http_response_code(500);
echo "Oops! Something went wrong and we couldn't send your message.";
}
}
else {
echo 0;
};
?>
九州编程