Hi all, if someone could help me fix an issue i'm having on a php website i would be very appreciative! Basically, one part of the php sends an email reminder for a meeting. It works correctly although it sends 2 copies of the emails to each recipient, which is not what i would like. The code for the bit that sends the reminder is below, hopefully it's enough, it's a group coursework and wasn't written by me, but none of us have been able to fix it yet.
Code:
if($remind==1)
{
list($year, $month, $day) = split('-', $odate);
$odue=$day."/".$month."/".$year;
#Sends e-mail reminder
$mailmeeting="SELECT s.StudentName, s.Email, me.Date, me.Time, me.Place, g.GroupName, m.ManagerEmail
FROM `Meeting` me, `Student` s, `Group` g, `GroupMember` gm, `ManagerGroup` mg, `Manager` m
WHERE m.ManagerID = '$managerid'
AND mg.ManagerID = m.ManagerID
AND me.ManagerID = mg.ManagerID
AND g.GroupID = $groupid
AND gm.GroupID = g.GroupID
AND mg.GroupID = mg.GroupID
AND me.GroupID = gm.GroupID
AND me.Time='$otime'
AND me.Date='$odate'
AND me.Place='$oplace'
AND s.StudentID = gm.StudentID";
$mailmeetings = mysql_query($mailmeeting,$connection);
$notify=1;
while($row=mysql_fetch_array($mailmeetings))
{
$to = "$row[1]";
$subject = "COA281 - Reminder for Meeting for $odue at $row[3] in $row[4].";
$message = "This is to remind you that your group $row[5] has a meeting scheduled for $odue at $otime in $oplace.";
$from = "$row[6]";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
if($notify==1)
{
$to = "$row[6]";
$subject = "COA281 - Reminder for Meeting for $odue at $row[3] in $row[4]. ";
$message = "This is to remind you that you have scheduled a meeting for group $row[5] at the above date, time and place.";
$from = "$row[6]";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
$notify=$notify+1;
}
}
echo"<p>Reminder sent.<p>";
}
I'm not sure this piece of code is the culprit because it is very similar to other pieces that work, i was wondering if maybe the page was loading twice, sending the emails twice, but i can't see how this would happen. I tried putting counters in the if statement to see how many times things were happening and the values the showed indicated that the if statement was performing correctly and that the correct number of records are being retrieved from the database etc, so maybe the page is loading twice. If anyone can help, again i would be very appreciative, this is driving me crazy and i need to get on with other work. Oh i've only been doing php/mysql for a few weeks so sorry if there's any glaring mistakes!
Thanks
Andy