sending email with all products from cart

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 04:30:33

问题


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" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
        $headers .= 'From: <blah@blah.com>' . "\r\n";

        $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:


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" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <blah@blah.com>' . "\r\n";

$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);


来源:https://stackoverflow.com/questions/31271599/sending-email-with-all-products-from-cart

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!