我正在使用 XAMPP,我想從數(shù)據(jù)庫表中選擇一個隨機記錄并通過電子郵件發(fā)送。我正在使用測試郵件服務(wù)器工具,但收到下一個錯誤:警告:mail():第 24 行 C:\xampp\htdocs\dailyapp\sender2.php 中的錯誤消息返回路徑 糟糕!出了點問題,我們無法發(fā)送您的消息。這里可能發(fā)生什么?任何想法?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 = "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;};?>
1 回答

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