HTML and Email Receipts

After an order has been processed, the winestore application confirms the shipping of the wines through both an email and an HTML receipt. The order/order-step4.php script sends the user an email. In turn, the order/order-step4.php script redirects to the order/receipt.php script which produces the HTML receipt.

The HTML receipt can be visited again at a later time by bookmarking the URL. As it carries out no database updates, it doesn't suffer from the reload problem described in Chapter 6. The receipt functionality is separated into two scripts so that returning to the HTML receipt doesn't cause an additional email receipt to be sent to the customer.

Email Receipt

Example 19-4 shows the order/order-step4.php script that sends an email receipt to the user. The function send_confirmation_email( ) creates the email body, destination address, subject, and additional headers of an email message, and then sends that email message. To do so, it uses the template that's shown in Example 19-5 and stored in the file templates/email.tpl.

Example 19-4. The order/order-step4.php script sends an order confirmation as an email

<?php // This script sends the user a confirmation email for their order // and then redirects to an HTML receipt version // By default, this script uses PEAR's Mail package. // To use PHP's internal mail( ) function instead, change "true" to "false" // in the following line define("USE_PEAR", true); require_once "DB.php"; require_once "HTML/Template/ITX.php"; ...

Get Web Database Applications with PHP and MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.