Jump to content

PhpMailer is sending the same body in loop


coldfission

Recommended Posts

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();
}

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.