0

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

3
Contributors
4
Replies
22
Views
4 Years
Discussion Span
Last Post by urbanthistleuk
2
$message .= $rows['1st_body'];

should be

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

Is that right?

0

also maybe:

$sql="UPDATE db SET 2nd_email_sent ='1' WHERE 2nd_email_sent ='0' AND stage_two = '1'";
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.