【问题标题】:Shopping Cart to Email购物车到电子邮件
【发布时间】:2017-03-09 15:45:01
【问题描述】:

希望有人可以帮助或指导我指导教程?

我有一个简单的购物车 (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>

【问题讨论】:

    标签: php forms mysqli shopping-cart


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多