购物车到电子邮件

时间:2017-03-09 15:45:01

标签: php forms mysqli shopping-cart

希望有人可以在教程的指导下协助或发送给我?

我有简单的购物车(PHP / MYSQLi),它处理订单并将它们存储在数据库中。 但是,我无法弄清楚最好的方法是如何发送包含订单确认详细信息的电子邮件提醒?

下面是checkout.php的代码 - 这是它提交到数据库的时间。

我也有ordersuccess.php - 这只是确认OrderID的页面。

我应该为ordersuccess.php实现一个脚本吗?

先谢谢大家,这对我来说都是学习曲线!

  

checkout.php

    <?php
// include database configuration file
include 'dbConfig.php';

// initializ shopping cart class
include 'Cart.php';
$cart = new Cart;

// redirect to home if cart is empty
if($cart->total_items() <= 0){
    header("Location: index.php");
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Checkout</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style>
    .container{width: 100%;padding: 50px;}
    .table{width: 65%;float: left;}
    .shipAddr{width: 30%;float: left;margin-left: 30px;}
    .footBtn{width: 95%;float: left;}
    .orderBtn {float: right;}
    </style>
</head>
<body>
<div class="container">
    <h1>Order Preview</h1>
    <table class="table">
    <thead>
        <tr>
            <th>Scent</th>
            <th>Type</th>
            <th>Price</th>
            <th>Qty</th>
            <th>Subtotal</th>
        </tr>
    </thead>
    <tbody>
        <?php
        if($cart->total_items() > 0){
            //get cart items from session
            $cartItems = $cart->contents();
            foreach($cartItems as $item){
        ?>
        <tr>
            <td><?php echo $item["name"]; ?></td>
            <td><?php echo $item["category"]; ?></td>
            <td><?php echo '£'.$item["price"].' GBP'; ?></td>
            <td><?php echo $item["qty"]; ?></td>
            <td><?php echo '£'.$item["subtotal"].' GBP'; ?></td>
        </tr>
        <?php } }else{ ?>
        <tr><td colspan="4"><p>No items in your cart......</p></td>
        <?php } ?>
    </tbody>
    <tfoot>
        <tr>
            <td colspan="4"></td>
            <?php if($cart->total_items() > 0){ ?>
            <td class="text-left"><strong>Total <?php echo '£'.$cart->total().' GBP'; ?></strong></td>
            <?php } ?>
        </tr>
    </tfoot>
    </table>

    <div class="footBtn">
        <a href="index.php" class="btn btn-warning"><i class="glyphicon glyphicon-menu-left"></i> Continue Shopping</a>
        <a href="cartAction.php?action=placeOrder" class="btn btn-success orderBtn">Place Order <i class="glyphicon glyphicon-menu-right"></i></a>
    </div>
</div>
</body>
</html>
  

ordersucess.php

<?php
if(!isset($_REQUEST['id'])){
    header("Location: index.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Order Success</title>
    <meta charset="utf-8">
    <style>
    .container{width: 100%;padding: 50px;}
    p{color: #34a853;font-size: 18px;}
    </style>
</head>
</head>
<body>
<div class="container">
    <h1>Order Status</h1>
    <p>Your order has submitted successfully. Order ID is #<?php echo $_GET['id']; ?></p>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

发送电子邮件可能会很慢并且阻塞。您应该将发送电子邮件移至后台作业。最简单的方法是创建命令/消息队列并编写队列的工作者/使用者。 前一段时间我使用swiftmailerSymfony2

进行了此操作
  

但是,您可能希望避免Swift Mailer与电子邮件传输之间通信的性能损失,这可能导致用户在发送电子邮件时等待下一页加载。

相关问题