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

时间:2015-07-07 14:33:36

标签: php email mysqli

首先,当谈到编码时,我会尝试解释 我试图将包含Cart表中所有产品的电子邮件发送给客户,但我发送的只是购物车表的最后一行,当我回复var时,它会打印给我所需的所有产品。< / p>

$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 个答案:

答案 0 :(得分:0)

我改变了你的代码,请看这里

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