I have an Order success page where you are directed to if your order is successful and it also updates your Order Status to Success. Why is my email not sending off to the user?
<?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();
}
?>
Please ignore the message that I am sending, it's from an example and I'm not actually going to use this. I am simply trying to get the email to send when the Order Status is set to Success.
What is wrong?