php - 为什么我的电子邮件没有从使用 PHP 的订单成功页面发送

标签 php mysql

我有一个订单成功页面,如果您的订单成功,您会被定向到该页面,它还会将您的订单状态更新为成功。为什么我的电子邮件没有发送给用户?

<?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/

相关文章:

php - 调用 mysqli_error() 时出现警告

mysql - SQL数据库设计-三个表: product,销售订单和采购订单-如何存储产品数量?

mysql - 在MySQL中创建用户而不删除、更新和更改权限

php - 获取上周一 - 周日的日期 : Is there a better way?

php - mysql_insert_id 不工作

javascript - 重启后检查本地服务器

php - 将 php 输出保存在文件中

当变量不满足要求时PHP重复一个函数

javascript - 如何使用PHP从复选框中获取值?

php - Magento 中过滤器搜索时的自定义网格中未返回产品名称