function emailReceipt($db_conn, $id) { // get the customer information from the database $customer = tcCustomer::getCustomerById($db_conn, $id); $totalPoints = tcVisits::getTotalPointsById($db_conn, $id); $toAddr = $customer->email; $subject = "Thanks for visiting Classic Polish 168!"; $msg = ""; $header = "MIME-Version: 1.0" . "\r\n"; $header .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $param = "-FClassicPolish168"; // populate the email body $visits = new tcVisits($id, $db_conn); $visits->initVisits(); $msg = $msg . '<html>'; $msg = $msg . '<head><title>Visit History</title></head>'; $msg = $msg . '<body>'; $msg = $msg . '<p>Dear ' . "{$customer->fname} {$customer->lname}:"; $msg = $msg . '<p>Below is a copy of your visit history and point balance for your reference.'; $msg = $msg . 'We look forward to serve you again. Have a great day!</p>'; $msg = $msg . '<table align="center" border="1">'; $msg = $msg . '<th>Date</th>'; $msg = $msg . '<th>Points</th>'; for ($i = 0; $i < count($visits->visits); ++$i) { $msg = $msg . '<tr>'; $msg = $msg . '<td align="center">' . $visits->visits[$i]->dtime . '</td>'; $msg = $msg . '<td align="right">' . $visits->visits[$i]->point . '</td>'; $msg = $msg . '</tr>'; } $msg = $msg . '<tr>'; $msg = $msg . '<td align="left"><strong>Balance:</strong></td>'; $totalPtrs = tcVisits::getTotalPointsById($db_conn, $id); $msg = $msg . '<td align="right">' . $totalPtrs . '</td>'; $msg = $msg . '</tr>'; $msg = $msg . '</table>'; $msg = $msg . '</body>'; $msg = $msg . '</html>'; if (mail($toAddr, $subject, $msg, $header, $param)) { $infoMsg = "Email sent successfully to {$customer->fname} {$customer->lname}!"; if (isset($_POST["id"])) { print $msg; print '<br/>'; print '<p align="center"><font color="green" size=20><strong>' . $infoMsg . '</strong></font></p>'; header("refresh:5; url=showdetails.php?custId=" . $id); } else { print $infoMsg; } } else { $errorMsg = "Failed to send email to {$customer->fname} {$customer->lname} with email {$customer->email}!"; if (isset($_POST["id"])) { print '<p align="center"><font color="red" size=20><strong>' . $errorMsg . '</strong></font></p>'; } else { print $errorMsg; } } }
public function showDetailTable() { print '<table align="center" border="1">'; // write the table header information writeTableHeader(array("Name", "Phone", "Email", "Date", "Points")); // write the table row to the web page writeTRBegin(); writeTDArray(array("{$this->fname} {$this->lname}", $this->phone, $this->email)); print '<td colspan=2></td>'; writeTREnd(); $visits = new tcVisits($this->custId, $this->db_conn); $visits->initVisits(); $numVisits = count($visits->visits); // NOTE: rowspan number has to plus 2 for unknown reason print '<td colspan=3 rowspan=' . ($numVisits + 2) . '></td>'; for ($i = 0; $i < $numVisits; ++$i) { writeTRBegin(); writeTD($visits->visits[$i]->dtime); writeTD($visits->visits[$i]->point, "right"); writeTREnd(); } $totalPtrs = tcVisits::getTotalPointsById($this->db_conn, $this->custId); writeTRBegin(); writeTD("Balance:"); writeTD($totalPtrs, "right"); writeTREnd(); print '</table>'; }