简体   繁体   English

发送电子邮件提醒(while循环)

[英]Sending Email Reminder (while loop)

I'm testing this code out. 我正在测试此代码。 I assigned two reminders with test date and time values. 我为两个提醒分配了测试日期和时间值。 Two reminders should be sent out to two different people. 应该向两个不同的人发送两个提醒。 However when I run it, one will get an email containing their reminder, while the other person receives an email containing both his and the other reminder in the body of the email 但是,当我运行它时,一个人将收到一封包含其提醒的电子邮件,而另一个人在该电子邮件的正文中收到一封包含他和另一个提醒的电子邮件

Any help would be much appreciated. 任何帮助将非常感激。

Thanks! 谢谢!

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

?> ?>

请在循环中为每个邮件重设hinter_details的值。

You need to reset the reminder_details to blank between loop iterations. 您需要在循环迭代之间将reminder_details重置为空白。

Simply change these lines: 只需更改以下行:

while($row = mysqli_fetch_array($your_reminder))
{   $reminder_owner = $row["reminder_owner"];
    //echo $reminder_owner;

To this: 对此:

while($row = mysqli_fetch_array($your_reminder))
{   $reminder_owner = $row["reminder_owner"];
    $reminder_details = "";
    //echo $reminder_owner;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM