我有一个订单成功页面,如果您的订单成功,您会被定向到该页面,它还会将您的订单状态更新为成功。为什么我的电子邮件没有发送给用户?
<?php
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (strpos($url,'order-success') !== false) {
$servername = "REMOVED";
$username = "REMOVED";
$password = "REMOVED";
$dbname = "REMOVED";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check Connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE orders SET Status = 'Success' WHERE Status = 'Incomplete' AND Username = '{$_SESSION['Username']}' ORDER BY OrderID DESC LIMIT 1;";
echo $sql;
if ($conn->query($sql) === TRUE) {
$to .= ''. $_SESSION['Username']. '';
$subject = 'Order Confirmation';
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th>
<th>Day</th>
<th>Month</th>
<th>Year</th>
</tr>
<tr>
<td>Joe</td>
<td>3rd</td>
<td>August</td>
<td>1970</td>
</tr>
<tr>
<td>Sally</td>
<td>17th</td>
<td>August</td>
<td>1973</td>
</tr>
</table>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
}
else {
session_destroy();
}
$conn->close();
}
?>
请忽略我发送的消息,它来自一个示例,我实际上并不打算使用它。我只是想在订单状态设置为成功时获取要发送的电子邮件。
怎么了?
最佳答案
首先,mail() 函数根据成功返回 true 或 false,检查一下
其次,检查您的垃圾邮件文件夹中的电子邮件,有 numerous ways to approach this problem
关于php - 为什么我的电子邮件没有从使用 PHP 的订单成功页面发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32647800/