2015-06-20 32 views
0

我創建了一個php電子郵件發送訂單後發出。我不確定我在做什麼錯,因爲如果我有多種不同類型的產品,電子郵件只會發送第一個添加的產品。從Authorize.net發送的交易收據包括訂單中的所有產品,但不包括我的電子郵件。我沒有收到任何錯誤,並且電子郵件發送正常。即使有多個產品訂購,只有一種產品在php電子郵件中列出

$to = $email; 
$subject = 'Your Example order'; 
$message = '<img src="'.$logoImage.'">'; 
$message = ' 
<html> 
<head> 
    <title>Example Order</title> 
</head> 
<body> 
    <p>Thank you for ordering with us!</p> 
     <p>Your order was successfully sent to us and we will start processing it immediately.</p><br><br> 
     <p>A charge of $'.$total_price.' was taken from '.$billToName.'\'s account that was sent with the order. 
     <p>Your order contained:</p> 
     <p> '.$prdqty.' - '.$prdsize.' - '.$prdname.'</p><br><br> 
     <p>'. $AuthorrizeResponseText.';</p><br><br> 
     <p>We really appreciate your business!</p> 
</body> 
</html> 
'; 
$from = "[email protected]"; 
$cc = "[email protected]"; 

// To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 

// Additional headers 
$headers .= 'To: ' .$to. "\r\n"; 
$headers .= 'From: ' .$from. "\r\n"; 
$headers .= 'Cc: '.$cc. "\r\n"; 

// Send the email 
mail($to,$subject,$message,$headers); 

我有問題,該生產線是這個...

<p> '.$prdqty.' - '.$prdsize.' - '.$prdname. $post_values.'</p> 

我需要它包括所有都是在訂單,而不僅僅是一個產品的不同。我以同樣的方式在我的網站上抓取產品。從我的數據庫輸出它們,然後通過整個站點的會話進行傳輸。我還會發送攜帶同一會話的電子郵件。這是如何變量的結構...

foreach($_SESSION['shopping_cart'] as $id => $product) { 
     $product_id = $product['product_id']; 
     $prdname = $products[$product_id]['product_name']; 

有沒有辦法,我可以做到這一點,或者我失蹤了嗎?

更新: 我寫了這個代碼,但它僅包括

<p>'. $AuthorrizeResponseText.';</p><br><br> 
     <p>We really appreciate your business!</p> 


$to = $email; 
$subject = 'Your Example order'; 
$message = '<img src="'.$logoImage.'">'; 
$message = ' 
<html> 
<head> 
    <title>Example Order</title> 
</head> 
<body> 
    <p>Thank you for ordering with us!</p> 
     <p>Your order was successfully sent to us and we will start processing it immediately.</p><br><br> 
     <p>A charge of $'.$total_price.' was taken from '.$billToName.'\'s account that was sent with the order. 
     <p>Your order contained:</p><br><ul>'; 
foreach($_SESSION['shopping_cart'] as $id => $product) { 
     $product_id = $product['product_id']; 
     $prdname = $products[$product_id]['product_name']; 
     $prdprice = $products[$product_id]['price']; 
     $prdqty = $product['quantity']; 
     $prdsize = $product['size']; 
$message .= '<li>' .$prdqty.' - '.$prdsize.' - '.$prdname.'</li><br>';    
        } 
$message .= '</ul>'; 
$message =' 

     <p>'. $AuthorrizeResponseText.';</p><br><br> 
     <p>We really appreciate your business!</p> 
</body> 
</html> 
'; 
$from = "[email protected]"; 
$cc = "[email protected]"; 

任何想法,對什麼是錯後的部分?

+0

您訂購的產品在哪裏?你可以使用一個foreach,但你需要創建一個有序的項目數組,然後你可以做foreach。 –

+0

答案是你提供的foreach循環 - 所以試試吧 – 2015-06-20 03:34:39

+0

我剛剛更新了我試過的問題。它悲慘地失敗了。請原諒我對此的無知。 – Becky

回答

1

可以包括分開$message variable.I之間foreach循環不知道你的數據庫結構,你的會話所包含的,但嘗試這樣

$message = '<img src="'.$logoImage.'">'; 
$message .= ' 
<html> 
<head> 
    <title>Example Order</title> 
</head> 
<body> 
    <p>Thank you for ordering with us!</p> 
     <p>Your order was successfully sent to us and we will start processing it immediately.</p><br><br> 
     <p>A charge of $'.$total_price.' was taken from '.$billToName.'\'s account that was sent with the order. 
     <p>Your order contained:</p>'; 
foreach($_SESSION['shopping_cart'] as $product) { 
    $product_id = $product['product_id']; 
    $prdname = $product[$product_id]['product_name']; 
    // And so on for each field you need 
    echo '<p> '.$prdqty.' - '.$prdsize.' - '.$prdname.'</p><br><br>'; 
} 

$message .= '<p>'. $AuthorrizeResponseText.'</p><br><br> 
     <p>We really appreciate your business!</p> 
</body> 
</html> 
'; 

東西不要忘記$var = "value"是給價值變量,但$var .= "add more"用於增加新的值並保持舊的。如果您只是再次輸入=,則舊值將被替換爲新值。

+0

好的,我添加了這個,我得到的一切除了... echo'

'。$ prdqty。' - '。$ prdsize'。' - '。$ prdname。'



';它顯示空白。 – Becky

+0

這只是錯誤的,它不應該被回顯,它應該被添加到$消息變量 – 2015-06-20 06:34:52

+0

這取決於他他會做什麼。我告訴他,我不知道他的DB結構和他的SESSION包含的內容。但你的回答是正確的。它應該推到'$ message'而不是回顯它,我犯這個錯誤因爲我在夜班的早上5點寫了這個。所以是的,instad呼應,試試'$ message。='

'。$ prdqty。' - '。$ prdsize'。' - '。$ prdname。'



';' – Aleksandar

相關問題