I have not faced any problems sending email to a particular user, but the problem occurred when I tried sending the similar message to all emails found in the database (MYSQL).
If I have 4 users found in the database, it still sends to all the 4 users, but the similar content of the email is repeated 4 times. If 250 users found, then 250 repeated contents.
The code snippet of the code is as such, been meddling with it, tested it for many times, and I ran out of ideas. Thanks for looking, any help is much appreciated…
} elseif ($temptarget == 'Parents'){
$g1chk = mysql_query("SELECT * FROM wmsidb WHERE s_stat='ACTIVE'");
$g1found = mysql_num_rows($g1chk);
While ($rowg1 = mysql_fetch_array($g1chk)){
$tempemail1 = $rowg1['g1_email'];
$tempemail2 = $rowg1['g2_email'];
$comments = (stripslashes($_POST['message']));
$to = "Parent <$tempemail1>, Parent / Guardian <$tempemail2>" . "\r\n";
$subject = "[$anndate] Announcement ::: $temptitle";
// Main Headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
// Additional Headers
$headers .= "From: Contact Us <mailer@mailer.com>" . "\r\n";
$message .= "
<table align='center' border='0' width='100%' cellpadding='6'>
<tr><td width='100%' align='left' bgcolor='#33327e'><font face='Arial' size='4' color='#ffffff'><b>" . strtoupper($temptitle) . "</b></font></td></tr></table>
<table align='center' border='0' width='100%' cellpadding='3'>
<tr><td width='10%' align='right'><font face='Arial' color='#636363'> date </font></td><td width='90%' align='left'><font face='Arial'>" . $tempdd . " " . strtoupper($tempmm2) . " " . $tempyear . "</font></td></tr>
<tr><td width='10%' align='right'><font face='Arial' color='#636363'> posted by </font></td><td width='90%' align='left'><font face='Arial'>" . $temppost . "</font></td></tr>
<tr><td width='10%' align='right' valign='top'><font face='Arial' color='#636363'> message </font></td><td width='90%' align='left'><font face='Arial'>embedded below...</font></td></tr>
</table>
<br/>
<table align='center' style='border:1px solid grey' width='95%' cellpadding='18'>
<tr><td width='100%' align='left'><font face='Arial'>" . $comments . "</font></td></tr>
</table>
<br/>";
if ($tempfeedback == 'Yes'){
$message .= "
<table align='center' border='0' width='100%' cellpadding='3'>
<tr><td width='10%' align='right'><font face='Arial' color='#636363'> feedback </font></td><td width='90%' align='left'><font face='Arial'>We need you to provide us a response to announcement above.</font></td></tr>
<tr><td width='10%' align='right'><font face='Arial' color='#636363'></font></td><td width='90%' align='left'><font face='Arial'>Please complete the 'Feedback Form' found in the link below. Thank you!</font></td></tr>
<tr><td width='10%' align='right'><font face='Arial' color='#636363'> link </font></td><td width='90%' align='left'><font face='Arial'><b><a href='' target='_blank'>link</a></b></font></td></tr>
</table>";
} else {
$message .= "
<table align='center' border='0' width='100%' cellpadding='3'>
<tr><td width='10%' align='right'><font face='Arial' color='#636363'> feedback </font></td><td width='90%' align='left'><font face='Arial'>No feedback required.</font></td></tr>
</table>";
}
$message .= "
<p><font face='Arial'><br/>
<br/><br/>
Footer with contact information
</font></p>";
mail ($to,$subject,$message,$headers);
}
echo "<tr><td width='80%' align='right'><font face='Arial' color='#636363'>" . $g1found . " emails sent to parents / guardians </font></td><td width='20%' align='middle'><font face='Arial'>OK</font></td></tr>";
echo "<tr><td width='80%' align='right'><font face='Arial' color='#252525'>module terminated</font></td><td width='20%' align='middle'><font face='Arial'></font></td></tr>";
echo "</table>";
Sure it does.
The variable message is being populated each time the loop runs, so at the beginning of each loop do:
$message= "";