发送电子邮件提醒(while 循环)
Sending Email Reminder (while loop)
我正在测试这段代码。我分配了两个带有测试日期和时间值的提醒。应该向两个不同的人发送两个提醒。然而,当我 运行 它时,一个人会收到一封包含他们的提醒的电子邮件,而另一个人会收到一封电子邮件 在电子邮件正文中包含他和另一个提醒
如有任何帮助,我们将不胜感激。
谢谢!
<?
date_default_timezone_set("America/Los_Angeles");
//$trigger_date = date('h:i \P\S\T');
//$trigger_time = date('h:i A');
//test date and time
$trigger_date = date('Y-m-d');
$trigger_time = date('04:51');
$your_reminder = mysqli_query($conn,"SELECT * FROM reminders WHERE reminder_date = '$trigger_date' AND reminder_time = '$trigger_time'");
$todaydate = date("Y-m-d");
$row = $your_reminder->num_rows;
if ($row == 0 ){
echo "Nothing to Send</div>";
} else {
while($row = mysqli_fetch_array($your_reminder))
{ $reminder_owner = $row["reminder_owner"];
//echo $reminder_owner;
//echo "<br>Title:".$row["reminder_title"];
$send_owner = mysqli_query($conn,"SELECT * FROM admin WHERE username='$reminder_owner'");
$row_owner = mysqli_fetch_array($send_owner,MYSQLI_ASSOC);
$email = $row_owner["admin_email"];
$headers = 'From: TeamInfoPage';
$email_subject ="Reminder Test: ".$row["reminder_title"];
$reminder_details .= "Hi ".$row_owner["admin_fn"]."\n";
$reminder_details .= "Event: ".$row["reminder_title"]."\n";
// $reminder_details .= $row["tasks_notes"]."\n\n";
//Send out Reminder mail
'X-Mailer: PHP/' . phpversion();
@mail($email, $email_subject, $reminder_details, $headers);
}
echo "Success";}
?>
请在每封邮件的循环中重置 reminder_details 的值..
您需要在循环迭代之间将 reminder_details
重置为空白。
只需更改这些行:
while($row = mysqli_fetch_array($your_reminder))
{ $reminder_owner = $row["reminder_owner"];
//echo $reminder_owner;
为此:
while($row = mysqli_fetch_array($your_reminder))
{ $reminder_owner = $row["reminder_owner"];
$reminder_details = "";
//echo $reminder_owner;
我正在测试这段代码。我分配了两个带有测试日期和时间值的提醒。应该向两个不同的人发送两个提醒。然而,当我 运行 它时,一个人会收到一封包含他们的提醒的电子邮件,而另一个人会收到一封电子邮件 在电子邮件正文中包含他和另一个提醒
如有任何帮助,我们将不胜感激。
谢谢!
<?
date_default_timezone_set("America/Los_Angeles");
//$trigger_date = date('h:i \P\S\T');
//$trigger_time = date('h:i A');
//test date and time
$trigger_date = date('Y-m-d');
$trigger_time = date('04:51');
$your_reminder = mysqli_query($conn,"SELECT * FROM reminders WHERE reminder_date = '$trigger_date' AND reminder_time = '$trigger_time'");
$todaydate = date("Y-m-d");
$row = $your_reminder->num_rows;
if ($row == 0 ){
echo "Nothing to Send</div>";
} else {
while($row = mysqli_fetch_array($your_reminder))
{ $reminder_owner = $row["reminder_owner"];
//echo $reminder_owner;
//echo "<br>Title:".$row["reminder_title"];
$send_owner = mysqli_query($conn,"SELECT * FROM admin WHERE username='$reminder_owner'");
$row_owner = mysqli_fetch_array($send_owner,MYSQLI_ASSOC);
$email = $row_owner["admin_email"];
$headers = 'From: TeamInfoPage';
$email_subject ="Reminder Test: ".$row["reminder_title"];
$reminder_details .= "Hi ".$row_owner["admin_fn"]."\n";
$reminder_details .= "Event: ".$row["reminder_title"]."\n";
// $reminder_details .= $row["tasks_notes"]."\n\n";
//Send out Reminder mail
'X-Mailer: PHP/' . phpversion();
@mail($email, $email_subject, $reminder_details, $headers);
}
echo "Success";}
?>
请在每封邮件的循环中重置 reminder_details 的值..
您需要在循环迭代之间将 reminder_details
重置为空白。
只需更改这些行:
while($row = mysqli_fetch_array($your_reminder))
{ $reminder_owner = $row["reminder_owner"];
//echo $reminder_owner;
为此:
while($row = mysqli_fetch_array($your_reminder))
{ $reminder_owner = $row["reminder_owner"];
$reminder_details = "";
//echo $reminder_owner;