购物车到电子邮件
Shopping Cart to Email
希望有人能帮助我或向我发送教程?
我有一个简单的购物车 (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>
发送电子邮件可能会很慢并且会阻塞。您应该将发送电子邮件移至后台作业。最简单的方法是创建一个command/message队列并写一个worker/consumer队列。
我前一段时间使用 swiftmailer with Symfony2
做到了这一点
You may, however, want to avoid the performance hit of the communication between Swift Mailer and the email transport, which could cause the user to wait for the next page to load while the email is sending.
希望有人能帮助我或向我发送教程?
我有一个简单的购物车 (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>
发送电子邮件可能会很慢并且会阻塞。您应该将发送电子邮件移至后台作业。最简单的方法是创建一个command/message队列并写一个worker/consumer队列。 我前一段时间使用 swiftmailer with Symfony2
做到了这一点You may, however, want to avoid the performance hit of the communication between Swift Mailer and the email transport, which could cause the user to wait for the next page to load while the email is sending.