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

时间:2016-03-15 18:43:22

标签: php loops email while-loop reminders

我正在测试此代码。我分配了两个带有测试日期和时间值的提醒。应该向两个不同的人发送两个提醒。但是,当我运行它时,会收到一封包含其提醒的电子邮件,而另一个人会收到一封电子邮件,其中包含他和电子邮件正文中的另一个提醒

非常感谢任何帮助。

谢谢!

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

&GT;

2 个答案:

答案 0 :(得分:1)

Plz在每个邮件的循环中重置reminder_details的值..

答案 1 :(得分:0)

您需要在循环迭代之间将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;