I have a function that sends multiple emails out depending on how many products are purchased within oscommerce. It works great until I add in the headers for the php mail() portion of the function. As you can see bellow, my headers read:
$headers .= 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
$headers .= "From: [email protected] rn" .
"Reply-To: [email protected] rn" .
"X-Mailer: PHP/" . phpversion();
But when I declare the headers (which I need in order to send the email as html), only the first email is sent out. Can I not send a header multiple times? Any suggestions would be appreciated!
Function snippet:
foreach ($dstToProduct as $dsid => $productIndices) {
$email = $newDropships[$dsid]['email'];
$subject = "A new order has been placed";
$headers .= 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
$headers .= "From: [email protected] rn" .
"Reply-To: [email protected] rn" .
"X-Mailer: PHP/" . phpversion();
// Build message text
$date = date('m/d/Y');
$text = '<table cellpadding="3" style="margin-top: 20px;"><tr style="background-color: #6d7d59; color: #ffffff; font-weight: bold; font-size: 12px;"><td style="width: 240px; vertical-align:text-top;">Product Name</td><td style="width: 120px; vertical-align:text-top;">Model Number</td><td style="width: 80px; vertical-align:text-top;">Quantity</td><td style="width: 80px; vertical-align:text-top;">Price</td></tr>';
foreach ($productIndices as $productIndex) {
$text .= '<tr style="background-color: #f0f0f0; color: #513311; font-size: 12px;"><td style="vertical-align:text-top;">' . $products_array[$productIndex]["text"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["model"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["qty"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["price"] . '</td></tr>';
}
$text .= '</table>';
if (!mail($email, $subject, $text, $headers)) {
mail('[email protected]', 'Error sending product', 'The following order was not sent: ' . $order_id);
}
}
}
4
Answers
You can try like this
Hope it should work for you…
your $headers is merging with the loop, try this. I am sure it will work:
If are you thinking that the phpversion() rise the problem, try something like this:
And generally, you don’t need to do this every time, the variables that is not specific user depends – you can declare once. something like this:
Try this :
}