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 = "donotreply@tackwholesale.com"; $mail->FromName = "TackWholesale.com"; $mail->AddReplyTo("tackman@tackwholesale.com", "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(); } Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.