dongpin4611 2015-07-07 14:33
浏览 97
已采纳

从购物车发送所有产品的电子邮件

first of all im a noob when it comes to coding but il try to explain im trying to send email with all the products from Cart table to a customer, but all I can send is the last row of the cart table, when im echoing the var's it prints to me all the products I need.

$message ="";
$message2 ="";

$trxformail = "select * from orders where trx_id = '$trx_id'";
$run_trx = mysqli_query($con, $trxformail);
while($post_trx = mysqli_fetch_array($run_trx)){
    $pro_id = $post_trx['p_id'];

    $pro_price = "select * from products where product_id='$pro_id'";
    $run_pro_price = mysqli_query($con,$pro_price);
    while($pp_price = mysqli_fetch_array($run_pro_price)){

        $product_price = array($pp_price['product_price']);
        $product_id = $pp_price['product_id'];
        $qty = $pp_price['product_qty'];
        $pro_name = $pp_price['product_title'];
        $pro_makat = $pp_price['product_makat'];
        $values = array_sum($product_price);
        $total +=$values*$p_price['qty'];    

        $headers = "MIME-Version: 1.0" . "
";
        $headers .= "Content-type:text/html;charset=UTF-8" . "
";
        $headers .= 'From: <blah@blah.com>' . "
";

        $subject = "פרטי ההזמנה שלכם באתר 'סלינה'";

        echo $pro_name;
        echo $qty;
        $message .= "<html> 
        <p dir='rtl'>
        שלום רב, <b style='color:#cc00cc;'>$c_name</b>, אנו מודים לכם על שקניתם אצלינו, ההזמנה שלכם תטופל בהקדם האפשרי. 
        </p>

        <table width='600' align='center' bgcolor='white' border='1' dir='rtl'>

        <tr align='center'><td colspan='6'><h2>פרטי ההזמנה שלכם</h2></td></tr>

        <tr align='center'>
        <th><b>מ.מ</b></th>
        <th><b>שם המוצר</b></th>
        <th><b>כמות</b></th>
        <th><b>שולם</th></th>
        <th>מספר ההזמנה</th>
        </tr>


        <tr align='center'>
        <td>1</td>
        <td>" . $pro_name . "</td>
        <td>" . $qty . "</td>
        <td>$total</td>
        <td>$invoice</td>
        </tr>     

        </table>
        </html>"; 
    }
  • 写回答

1条回答 默认 最新

  • douruocai4111 2015-07-07 14:49
    关注

    I changed your code around a little bit, see here

    <?php
    $message ="";
    $message2 ="";
    
    $trxformail = "select * from orders where trx_id = '$trx_id'";
    $run_trx = mysqli_query($con, $trxformail);
    
    while($post_trx = mysqli_fetch_array($run_trx)){
        $pro_id = $post_trx['p_id'];
    
        $pro_price = "select * from products where product_id='$pro_id'";
        $run_pro_price = mysqli_query($con,$pro_price);
        while($pp_price = mysqli_fetch_array($run_pro_price)){
    
            $product_price = array($pp_price['product_price']);
            $product_id = $pp_price['product_id'];
    
            $messageRows['qty'] = $pp_price['product_qty'];
            $messageRow['pro_name'] = $pp_price['product_title'];
            $messageRows['pro_makat'] = $pp_price['product_makat'];
            $values = array_sum($product_price);
            $messageRows['total'] = $values*$p_price['qty'];    
            $msg[]=$messageRows;
        }
    
    $headers = "MIME-Version: 1.0" . "
    ";
    $headers .= "Content-type:text/html;charset=UTF-8" . "
    ";
    $headers .= 'From: <blah@blah.com>' . "
    ";
    
    $subject = "פרטי ההזמנה שלכם באתר 'סלינה'";
    
    $message = "<html> 
    <p dir='rtl'>
    שלום רב, <b style='color:#cc00cc;'>$c_name</b>, אנו מודים לכם על שקניתם אצלינו, ההזמנה שלכם תטופל בהקדם האפשרי. 
    </p>
    
    <table width='600' align='center' bgcolor='white' border='1' dir='rtl'>
    
    <tr align='center'><td colspan='6'><h2>פרטי ההזמנה שלכם</h2></td></tr>
    
    <tr align='center'>
    <th><b>מ.מ</b></th>
    <th><b>שם המוצר</b></th>
    <th><b>כמות</b></th>
    <th><b>שולם</th></th>
    <th>מספר ההזמנה</th>
    </tr>";
    
    $i = 1;
    foreach($msg as $row){
        $message .= "<tr align='center'>
        <td>" . $i . "</td>
        <td>" . $row['pro_name'] . "</td>
        <td>" . $row['qty'] . "</td>
        <td>" . $row['total'] . "</td>
        <td>" . $invoice . "</td>
        </tr>";  
        $i++;
    }
    $message .= "</table></html>"; 
    
    mail($to,$subject,$message,$headers);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥15 爬取1-112页所有帖子的标题但是12页后要登录后才能 我使用selenium模拟登录 账号密码输入后 会报错 不知道怎么弄了
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline