我正在製作一個表單,用戶可以在其中建立一個購物車,然後一旦他們提交,他們將被帶到一個頁面,顯示他們的購物車中的最終內容。在幕後,PHP正在向我發送一封電子郵件,它需要包含已經在頁面上呈現的完全相同的表格,但是我不想再次重新構建表格,我想使用已經存在的表格建成。我不知道該怎麼做。我的代碼的作品,一切都是我想要的,所以不要再次顯示錶格沒有重新處理所有PHP
下面是一個代碼樣我喜歡的樣本,我剪掉了重複的東西,使它更容易看。
<table align="center" width="100%">
<thead align="center">
<tr>
<td style="border-color: #000000; background-color: #000000; color: #ffffff; border-style: solid; border-width: 1px;" class="head"><b>Product</b></td>
<td style="border-color: #000000; background-color: #000000; color: #ffffff; border-style: solid; border-width: 1px;" class="head"><b>Item ID</b></td>
<td style="border-color: #000000; background-color: #000000; color: #ffffff; border-style: solid; border-width: 1px;" class="head"><b>Quantity</b></td>
<td style="border-color: #000000; background-color: #000000; color: #ffffff; border-style: solid; border-width: 1px;" class="head"><b>Cost</b></td>
</tr>
</thead>
<tbody>
<?php
$i = 0;
$cmf073 = mysqli_result($result, $i, "cmf073");
$cmf073total = mysqli_result($result, $i, "cmf073total");
if($cmf073 > 0)
{?>
<tr>
<td align="center" style="border-color: #000000; background-color: #ffffff; border-style: solid; border-width: 1px;" class="body">
Printable 3-Up Certified Mail® Form
</td>
<td align="center" style="border-color: #000000; background-color: #ffffff; border-style: solid; border-width: 1px;" class="body">
CMF-073
</td>
<td align="center" style="border-color: #000000; background-color: #ffffff; border-style: solid; border-width: 1px;" class="body">
<?php echo number_format($cmf073 * 1000, 0) ." Forms";?>
</td>
<td align="center" style="border-color: #000000; background-color: #ffffff; border-style: solid; border-width: 1px;" class="body">
$<?php echo number_format($cmf073total, 2);?>
</td></tr>
<?php
}
echo "<tr border='0'><td></td><td></td><td></td><td align='center'><b>Cost Estimate: ";
echo "$".number_format($total, 2)."</b><br />
<font style='font-size: 8px;'>Plus Tax, Shipping and Handling</font></td></tr></tbody></table>";
}
$email = "[email protected]";
$subject = "New Customer Order Request from $company" ;
$message = "A new order request has been submitted on y.net</br></br>
Contact Info:</br>
$firstName $lastName</br>
$phone | $email</br>
$company</br>
$address1</br>
$address2</br>
$city, $state $zip";
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'Content-type: text/html; charset=utf-8' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email, $subject, $message, $headers);
所以我需要在代碼頂部已經生成的表格放在電子郵件$ message的底部。但是我不想再重新生成一切,因爲PHP已經創建了我需要的表。對不起,如果這是令人困惑的,我真的不知道如何解釋它。謝謝。
也許讓一個變量叫'$ table'這包含所有行等即'$表='
像smarty這樣的模板引擎可以緩存你的模板。 –