HTML and Email Receipts

Once an order has been processed, the winestore application confirms the shipping of the wines through both an email and an HTML receipt. The order.3 script redirects to the shipping.1 script shown in Example 12-2, which sends the user an email. In turn, the shipping.1 script redirects to the shipping.2 script shown in Example 12-3, which produces the HTML receipt. The HTML receipt can be visited again at a later time by bookmarking the URL and, 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.

The function send_confirmation_email( ) in Example 12-2 creates the destination address, the subject, the body, and additional headers of an email message, and then sends that email message. The destination to address is created using the firstname, the surname, and the email address of the customer so that, for example, it has the following format:

Michael Smith <mike@webdatabasebook.com>

The additional email headers are static and always have the following format:

From: "Hugh and Dave's Online Wines" <help@webdatabasebook.com>                                                                               
X-Sender: <help@webdatabasebook.com>                                                                                                          
X-Mailer: PHP                                                                                                                                 
X-Priority: 1
Return-Path: <help@webdatabasebook.com>

The subject of the email is always:

$subject = "Hugh and Dave's Online Wines: Order 
            Confirmation";

The body of the message ...

Get Web Database Applications with PHP, and MySQL 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.