<?php 
require 'database.php';
include('smtp/PHPMailerAutoload.php');

$cdate = date('Y-m-d');


$gettaskqry="select task_master.*,user_master.user_name,user_email,user_mobile from task_master 
inner join user_master ON user_master.user_id=task_master.task_userid 
where task_deleted='No' AND task_enddate <='$cdate' AND task_status!='Completed' order by task_id DESC";
$gettaskres=mysqli_query($con, $gettaskqry);
while($taskgetdata=mysqli_fetch_assoc($gettaskres))
{
	
$task_id = $taskgetdata['task_id'];
$status = $taskgetdata['task_status'] ?? '';
$taskusername=$taskgetdata['user_name'];
$taskuseremail=$taskgetdata['user_email'];
$taskusermobile='91'.$taskgetdata['user_mobile'];

$task_title=$taskgetdata['task_title'];
$task_priority=$taskgetdata['task_priority'];
$task_type=$taskgetdata['task_type'];
$task_enddate=$taskgetdata['task_enddate'];

$subject ='Task Reminder: Complete Your Assigned Task';
$message = '
<p>Dear <strong>'.$taskusername.',</strong></p>
<p>This is a friendly reminder regarding your assigned task.</p>
<p><strong>Task Details:</strong></p>
<p><strong>Task Name:</strong> '.$task_title.'<br>
<strong>Priority:</strong> '.$task_priority.'<br>
<strong>Type:</strong> '.$task_type.'<br>
<strong>Deadline:</strong> '.date('d-M-Y', strtotime($task_enddate)).'</p>

<p>Please ensure that the task is completed on or before the deadline.</p>
<p>If the task is already completed, kindly ignore this message.</p>
<br>

<p>Best Regards,</p>
<p><strong>'.$user_name.'</strong><br>
SNA Associates</p>
';


$mail = new PHPMailer();
$mail->SMTPDebug  = false;
$mail->isSMTP();
$mail->SMTPAuth   = true;
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 587; // TLS port
$mail->SMTPSecure = 'tls';
$mail->Username   = "notifications@snassociates.org.in";
$mail->Password   = "unjn wqld wlut cmzm"; // ❗ normal password नहीं चलेगा
$mail->isHTML(true);
$mail->CharSet = 'UTF-8';
$mail->setFrom("notifications@snassociates.org.in", "SNA Associates");
$mail->Subject = $subject;
$mail->Body    = $message;
$mail->addAddress($taskuseremail);
// Optional
$mail->SMTPOptions = [
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => false
    ]
];

if(!$mail->send()){
    //echo "Mail Error: " . $mail->ErrorInfo;
}else{
    //echo "Mail Sent Successfully";
}


}

?>
