coldfission Posted July 2, 2008 Share Posted July 2, 2008 The code below is supposed to send each recipient a different email body, but the same email body from the first item is being sent to everybody in the list. How do i get the body of the email to be reset for each email? $query = "SELECT orders_id, customers_name, customers_email_address FROM orders WHERE date_purchased LIKE '%$past_date%' AND orders_status=3"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); require_once "phpmailer/class.phpmailer.php"; $mail = new PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->IsHTML(true); $mail->Host = "localhost.localdomain"; // SMTP server $mail->From = "[email protected]"; $mail->FromName = "TackWholesale.com"; $mail->AddReplyTo("[email protected]", "Tackwholesale.com"); $mail->Subject = "Review your Purchased Items and take our Survey"; while ($row = mysql_fetch_array($result)) { $orders_id = $row['orders_id']; $enc_orders_id = ($orders_id*897)-411; $customers_email_address = $row['customers_email_address']; $customers_name = $row['customers_name']; $customers_name = explode(" ",$customers_name); $customers_name = $customers_name[0]; $feedback_email = str_replace('past_date', $past_date, $feedback_email); $feedback_email = str_replace('customers_name', $customers_name, $feedback_email); $feedback_email = str_replace('enc_orders_id', $enc_orders_id, $feedback_email); $mail->Body = $feedback_email; $mail->AddAddress($customers_email_address); if(!$mail->Send()) { echo "error"; } $mail->ClearAddresses(); } Link to comment https://forums.phpfreaks.com/topic/112969-phpmailer-is-sending-the-same-body-in-loop/ Share on other sites More sharing options...
ratcateme Posted July 2, 2008 Share Posted July 2, 2008 you need to copy $feedback_email because at the start of the first loop all the replaces take place but then they cant take place next loop because they have all ready been replaced change your code to $new_email = $feedback_email; $new_email = str_replace('past_date', $past_date, $new_email); $new_email = str_replace('customers_name', $customers_name, $new_email); $new_email = str_replace('enc_orders_id', $enc_orders_id, $new_email); $mail->Body = $new_email; Scott. Link to comment https://forums.phpfreaks.com/topic/112969-phpmailer-is-sending-the-same-body-in-loop/#findComment-580289 Share on other sites More sharing options...
coldfission Posted July 3, 2008 Author Share Posted July 3, 2008 wow what a stupid error. i didn't even think of that. thanks Link to comment https://forums.phpfreaks.com/topic/112969-phpmailer-is-sending-the-same-body-in-loop/#findComment-580515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.