user4317638
user4317638

Reputation:

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

?>

Upvotes: 0

Views: 232

Answers (2)

Bing
Bing

Reputation: 3171

You need to reset the reminder_details to blank between loop iterations.

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;

Upvotes: 0

Aju John
Aju John

Reputation: 2234

Plz reset the value of reminder_details in the loop for each mail..

Upvotes: 1

Related Questions