Hello,

First of all apologies if this has been posted before, having trouble findin the answer,

Let me start by inserting the code I have having the problem with, apologies if this isn't the correct way of doing things but I am still a newbie at php

<?php 

include('config.inc');

mysql_select_db($dbname); 
$sql="SELECT * FROM db, 1st_reminder WHERE stage_two = '1' AND 2nd_email_sent = '0'"; 
$result = mysql_query($sql) or die(mysql_error());

$count = 1;
while ($rows = mysql_fetch_array ($result)) {

$to  = $rows['contact_email']; 
$from = "email@domain.com";
$subject = "Subject";
$message .= $rows['1st_body'];
$headers = "From:" . $from; 
mail($to,$subject,$message,$headers);
    if ($count % 5 == 0) {
      sleep(5);
    }
    $count++;
}
$sql="UPDATE db SET 2nd_email_sent ='1' WHERE 2nd_email_sent ='0'";
$result=mysql_query($sql);

mysql_close();
?>

The issue I am having is if there is more than one email that goes out, (which will be the case once finished) the email is duplicated, so I get the email going to all the recipients but the body of the message is repeated, has any one got any ideas where I might be going wrong

This is a project I am working on for work, it generates email as reminders to customers, so it will be sending out several a day

Cheers
Martin

Member Avatar for diafol
$message .= $rows['1st_body'];

should be

$message = $rows['1st_body'];

Is that right?

Cheers, I'll check that later

also maybe:

$sql="UPDATE db SET 2nd_email_sent ='1' WHERE 2nd_email_sent ='0' AND stage_two = '1'";

Thanks guys, this worked a dream

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.