我已经做了一个订购系统,现在从产品表单到评审页面。我已经将页面设置为使用PHP循环来显示他们从上一页中选择了哪些产品,而且效果很好。现在,我需要一个“订单”按钮,电子邮件的订单。我的做法是编写较少的代码,我不想重新编写所有的代码来将此表单发送到另一个php表单上。有没有办法让电子邮件标题在这个页面上并将生成的html转储到要发送的电子邮件正文中?
下面是我如何循环上一页的表单内容。基本上,它是通过所有的产品,如果在那里,显示他们的评论。如果不是,不要。
for ($i=0; $i<8; $i++) {
if (!empty($_REQUEST['driver'][$i]['select'])) {
//add the club to the total of clubs
$club = $_REQUEST['driver'][$i]['select'];
array_push($club_total, $club);
//add the price to the cost
list($shaft, $price) = explode(":", $_REQUEST['driver'][$i]['shaft']);
array_push($cost, $price);
//show the user
echo '<h3>' .$_POST['driver'][$i]['name']. ' - $'. money_format('%i', $price).'</h3>';
echo '<ul>';
if (!empty($_REQUEST['driver'][$i]['left'])) {
echo '<li><strong>Left Handed</strong></li>';
}
echo '<li>Length: '.$_POST['driver'][$i]['length']. '"</li>';
echo '<li>Shaft: '.$shaft. '</li>';
if (!empty($_REQUEST['driver'][$i]['hossel'])) {
echo '<li>Purist Hossel: ' .$_POST['driver'][$i]['hossel'].'</li>';
}
if (!empty($_REQUEST['driver'][$i]['color'])) {
echo '<li>Purist Color: ' .$_POST['driver'][$i]['color'].'</li>';
}
echo '</ul>';
}发布于 2016-03-10 18:41:24
您可以在输出缓冲区中捕获html,然后将其存储在变量中供以后使用(如将其放入电子邮件正文中)。
ob_start();
for ($i=0; $i<8; $i++) {
// ... your code
}
$my_html = ob_get_contents();
ob_end_clean();然后将$my_html作为您的电子邮件体,并将其发送出去。
第一次将所有内容放入变量中的想法也很有效,但这可能会为重写所有内容节省一些精力。
发布于 2016-03-10 18:37:18
而不是回显html,构建一个字符串,因此$out .= "your“等等,然后您可以轻松地将该html块设置为电子邮件函数的主体。
我假设您知道如何编写代码,否则我将为您添加代码示例。
https://stackoverflow.com/questions/35924505
复制相似问题