I have a while loop that goes through the mysql_fetch_array, but is not giving me the correct results. I am trying to have it cycle through the dateabase and find all of the registrations that expire today. Then send each member a notice. It cycles though ok, however and the first person gets their email, however the second person gets the email from the first person and their own email. The thrid person would get all three. So i need to send a email then cycle through again and send a new clean email.

$row = mysql_fetch_array($result);


// Start cycle through transactions
while($row = mysql_fetch_array($result)){

$customer_contract = date('m/d', strtotime($row['transaction_date'])); 
$customer_contract_full = date('F d', strtotime($row['transaction_date'])); 

// Date change 						  
$contract_will_expire = strtotime ( $customer_contract  ) ;

$contract_will_expire = date ( 'm/d' , $contract_will_expire );


	// Start Customer Info
	 if($contract_will_expire == $current_date) {
		$email = $row['transaction_payer_email'];
		$customer_id = $row['transaction_customer_id']; 

		$name = $row['customer_name_first'] . ' ' . $row['customer_name_last'];



		// Star Email to Customer							
		$to = $email;
		$subject = "Annual Support Contract Renewal";


		$message .= "Dear ";
		$message .= $name;
		$message .= "<br /> <br /> ";

		$message .= "&nbsp;&nbsp;&nbsp;This message is to inform you that your annual service contract for $school will expire on $customer_contract_full. Your support contract entitles you free software updates, free technical support and discounts to other software packages that we offer. 
		<br> &nbsp;&nbsp;&nbsp; Renew Your Support Contract online by adding it to your cart and then login to your account with your email address and password then proceed with check out. If you wish to renwew your contract with a purchase order, you can let us know by replying to this email or give us a call. <br><br>";

		$message .= "Thank you, <br>";
		$message .= "Software 4 Schools Support Staff";

		// $headers = "From: Software 4 Schools <$email> \nContent-Type: text/html";
		// 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";
		$headers .= 'From: Software 4 Schools <support@mysite.com>' . "\r\n";
		$headers .= 'Bcc: ben@mysite.com' . "\r\n";

		$sent = mail($to, $subject, $message, $headers) ;

		//if($sent) {
		//	$message_follow_up = "Information E-Mail has been sent to client";
		//	}

		//if(isset($message_follow_up)) { 
		//	echo $message_follow_up;
		}
		// while ($contract_will_expire == $current_date);								

		// End Customer Info
		} 
							

    You are always concatanating to $message so it will just grow and grow.

    The first $message line should read $message = "Dear ";

    NOT $message.="Dear ";

    This will then start a "new" $message.

    The other variables such as header etc do this so probably just a typo!

    Cheers,

    Dave.

      Dave,
      Thank you for that. Worked perfect...

        No problem - hope you get plenty of renewals 🙂

          Write a Reply...