-1

我在向特定用户发送电子邮件时没有遇到任何问题,但是当我尝试将类似的消息发送到数据库(MYSQL)中找到的所有电子邮件时,问题就出现了。

如果我在数据库中找到了 4 个用户,它仍然会发送给所有 4 个用户,但是电子邮件的类似内容会重复 4 次。如果找到 250 个用户,则 250 个重复内容。

代码的代码片段是这样的,一直在插手,测试了很多次,我的想法就用完了。感谢您的关注,非常感谢您的帮助...

} 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>";
4

1 回答 1

2

当然可以。

每次循环运行时都会填充变量消息,因此在每个循环开始时执行:$message= "";

于 2013-02-05T12:30:15.540 回答