我的问题是,在提交表单时,它会发送一封电子邮件,提醒其他用户先前已为该营地位置输入了新调查条目的确切阵营的调查,问题是该人是否已输入3用户获得3封电子邮件的营地位置调查,因为我的数据库有时会为每个营地提供来自同一用户电子邮件的条目。
这就是问题所在
$ to_add = $ row ['电子邮件'];
如何确保多次不向用户发送电子邮件?
$query2 = "SELECT * FROM Camp_Survey_Submits WHERE CampName = '$campname3'";
$result = mysql_query($query2) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$from_add = "support@hikelospadres.com";
$to_add = $row['Email'];
$subject = "New Report Has Been Submitted to ".$row['CampName']." ";
$message = "Hello ".$row['SurveyorName'].", <br>
We noticed that you have previously filled out a survey for ".$row['CampName'].", so we just wanted to inform you that a new report has been added to ".$row['CampName'].". <br> To see this latest report, please go to: <a href='".$row['Referrer']."'><b> ".$row['Referrer']." </b></a>. <br>
Thank you,<br><br><br>
<b>Hike Los Padres<b><br>
www.hikelospadres.com<br>
`
答案 0 :(得分:0)
我要做的是在while
运行时将每封电子邮件输入到数组中,然后在电子邮件发送之前检查该电子邮件是否已存在于数组中。
这样做:
$query2 = "SELECT * FROM Camp_Survey_Submits WHERE CampName = '$campname3'";
$result = mysql_query($query2) or die(mysql_error());
$emails = array();
while($row = mysql_fetch_array($result)) {
if ( !in_array($row['Email'],$emails)) {
$from_add = "support@hikelospadres.com";
$to_add = $row['Email'];
$subject = "New Report Has Been Submitted to ".$row['CampName']." ";
$message = "Hello ".$row['SurveyorName'].", <br>
We noticed that you have previously filled out a survey for ".$row['CampName'].", so we just wanted to inform you that a new report has been added to ".$row['CampName'].". <br> To see this latest report, please go to: <a href='".$row['Referrer']."'><b> ".$row['Referrer']." </b></a>. <br>
Thank you,<br><br><br>
<b>Hike Los Padres<b><br>
www.hikelospadres.com<br>";
mail(); // send the mail using the mail function (or PHP Mailer, etc.)
array_push($emails,$row['Email']);
}
}
答案 1 :(得分:0)
尝试这样的事情:
$emails = array();
while($row = mysql_fetch_array($result)) {
$emails[$row['Email']] = array(
'from_add' => "support@hikelospadres.com",
'to_add' => $row['Email'],
'subject' => "New Report Has Been Submitted to ".$row['CampName'],
'message' => "Hello ".$row['SurveyorName']
);
}
foreach($emails as $email){
mail($email['to_add'], $email['subject'], $email['message']);
}
首先构建数组,通过电子邮件覆盖密钥,然后再循环发送。
也许有更好的方法,只是一个想法