我正在使用 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 connectionif ($conn->connect_error) { die("Connection failed: " . $conn->connect_error);}$recipient = "[email protected]";$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;};?>
1 回答

九州編程
TA貢獻1785條經驗 獲得超4個贊
像這樣添加和標題
$header = array(
'From' => '[email protected]',
'Reply-To' => '[email protected]',
'X-Mailer' => 'PHP/' . phpversion()
);
并輸入您自己的信息
并在郵件功能中使用它
mail($recipient, $subject, $message,$header)
- 1 回答
- 0 關注
- 97 瀏覽
添加回答
舉報
0/150
提交
取消