我有一个向用户显示他已添加到购物车中的产品的功能。在此函数中,我只是回显所有$ _SESSION数据。问题是我想通过电子邮件发送所有$ _SESSION数据。我不能将函数存储在变量中,并且只能使用$ message = $ function,因为在电子邮件中我什么也没显示。所以我的问题是:通过电子邮件发送$ _SESSION数据最简单的方法是什么?
我使用以下代码在php文件中显示所有会话:
function cart_summary() {
foreach($_SESSION as $name => $value) {
if ($value>0) {
if (substr($name, 0, 5)=='cart_') {
$id = substr($name, 5, (strlen($name)-5));
$id2 = mysql_real_escape_string((int)$id);
$get_colour_size_category = "SELECT * FROM products WHERE id='$id2'";
$result_colour_size_category = mysql_query($get_colour_size_category);
while ($get_colour_size_category_row = mysql_fetch_assoc($result_colour_size_category)) {
$get_webshop_category = $get_colour_size_category_row['webshop_category'];
$get_webshop_category2 = mysql_real_escape_string((int)$get_webshop_category);
$get_name_and_price = "SELECT * FROM webshop_categories WHERE id='$get_webshop_category2'";
$result_name_and_price = mysql_query($get_name_and_price);
$row_name_and_price = mysql_fetch_assoc($result_name_and_price);
$sub = $row_name_and_price['price'] *$value;
echo '<tr><td>'. $row_name_and_price['ev_name'] .' '. $get_colour_size_category_row['colour'].' '. $get_colour_size_category_row['size'].'</td><td class="value"> '. $value .' </td><td> €'.number_format($row_name_and_price['price'], 2).'</td><td> €'.number_format($sub, 2).'</td><td></td></tr>';
}
?><?
}
$total += $sub;
}
}
我想通过电子邮件发送此输出
通过执行以下操作,将$ _SESSION数据放入电子邮件中:
function cart_summary() {
$message = "";
foreach($_SESSION as $name => $value) {
if ($value>0) {
if (substr($name, 0, 5)=='cart_') {
$id = substr($name, 5, (strlen($name)-5));
$id2 = mysql_real_escape_string((int)$id);
$get_colour_size_category = "SELECT * FROM products WHERE id='$id2'";
$result_colour_size_category = mysql_query($get_colour_size_category);
while ($get_colour_size_category_row = mysql_fetch_assoc($result_colour_size_category)) {
$get_webshop_category = $get_colour_size_category_row['webshop_category'];
$get_webshop_category2 = mysql_real_escape_string((int)$get_webshop_category);
$get_name_and_price = "SELECT * FROM webshop_categories WHERE id='$get_webshop_category2'";
$result_name_and_price = mysql_query($get_name_and_price);
$row_name_and_price = mysql_fetch_assoc($result_name_and_price);
$sub = $row_name_and_price['price'] *$value;
$message .= '<tr><td>'. $row_name_and_price['ev_name'] .' '. $get_colour_size_category_row['colour'].' '. $get_colour_size_category_row['size'].'</td><td class="value"> '. $value .' </td><td> €'.number_format($row_name_and_price['price'], 2).'</td><td> €'.number_format($sub, 2).'</td><td></td></tr>';
}
?><?
}
$total += $sub;
}
return $message
}
完成此操作后,我可以通过电子邮件将函数的输出发送给
$message .= cart_email() . "\n";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句