我可以将功能输出数据发送到邮件吗?

时间:2011-05-27 13:06:08

标签: php

我有2个功能,我想将所有功能数据发送到我的邮箱 我试过这样的 这些是我的功能

function cart1();
function cart2();

我的功能代码

<?php
function cart1  () {
    foreach($_SESSION as $name => $value){
        if ($value>0) {
            if (substr($name, 0, 5)=='cart_') {
                $id = substr($name, 5, (strlen($name)-5));
                $get = mysql_query('SELECT id, name, price FROM products WHERE id='.mysql_real_escape_string((int)$id));
                while ($get_row = mysql_fetch_assoc($get)) {
                    $sub = $get_row['price']*$value;
                    echo $get_row['name'].' x '.$value.' @ &pound;'.number_format($get_row['price'], 2).' = &pound;'.number_format($sub, 2).'<a href="cart.php?remove='.$id.'">[-]</a> <a href="cart.php?add='.$id.'">[+]</a> <a href="cart.php?delete='.$id.'">[Delete]</a><br />';
                }
            }

        }
    }
}
?>

<form action="email.php" method="post">
    <input type="hidden" name="cart1" value="<?php cart1 (); ?>">
    <input type="hidden" name="cart2" value="<?php cart2 (); ?>">
    <input type="submit" name="submit" value="Submit" >
</form>

我只想知道如何将函数的输出转换为表单对象。任何1可以帮助我。

1 个答案:

答案 0 :(得分:1)

<?php
     function cart1() {
          $results = '';
          foreach(...) {
               ...
               $results .= $get_row['name'].' x '.$value.' @ &pound;'.number_format($get_row['price'], 2).' = &pound;'.number_format($sub, 2).'<a href="cart.php?remove='.$id.'">[-]</a> <a href="cart.php?add='.$id.'">[+]</a> <a href="cart.php?delete='.$id.'">[Delete]</a><br />';
          }
          return $results;
     }
?>



<input type="hidden" name="cart1" value="<?php echo cart1 (); ?>">
<input type="hidden" name="cart2" value="<?php echo cart2 (); ?>">
相关问题