<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';


//Load Composer's autoloader
require 'vendor/autoload.php';

// Create a new PHPMailer instance
$mail = new PHPMailer();

// Set up SMTP
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'aaadriversacademyca@gmail.com'; // Your Gmail email address
$mail->Password = 'vjqzkpbuigajmtcq'; // Your Gmail password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS
//$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 587;

// Sender information
$mail->setFrom('rishtadepot@gmail.com', 'Rishta Depot'); // Your Gmail email address and your name

// Recipient information
//$email_id   =$rowData->user_email_id;
//$contact_name  =$rowData->contact_name;
include("include/settings.php");


$where = 'where';

      
        // Fetch records for the current date
$condition .= ' DATE(cbi_call_schedule.call_scheduling) = CURDATE()';

// Fetch records 15 minutes before the current time
$condition .= ' AND TIME(cbi_call_schedule.call_scheduling) >= DATE_SUB(CURTIME(), INTERVAL 15 MINUTE)';

        
$select_query = "";
$select_query .= " select cbi_call_schedule.*, cdi_usermaster.user_full_name,cdi_usermaster.user_email_id, rishta_leadmaster.lead_allocated_to , rishta_leadmaster.contact_name, rishta_leadmaster.disposition ";
$select_query .= " from cbi_call_schedule inner join cdi_usermaster on cbi_call_schedule.call_added_by=cdi_usermaster.user_id ";
$select_query .= " inner join rishta_leadmaster on cbi_call_schedule.lead_id=rishta_leadmaster.lead_id ";
$select_query .= $where . " " . $condition;
$select_query .= " order by cbi_call_schedule.call_scheduling desc ";

$resultCallSchedule = $mysqli->prepare($select_query);
$resultCallSchedule->execute();
$resultCallSchedule = $resultCallSchedule->get_result();

while ($rowData = mysqli_fetch_object($resultCallSchedule)) {
    echo '<pre>';
print_r($rowData);
echo '</pre>';


$userFullName = $rowData->user_full_name;
$userEmail = $rowData->user_email_id;

$contact_name = $rowData->contact_name;

$disposition = $rowData->disposition;
$call_scheduling = $rowData->call_scheduling;
$call_time_scheduling = $rowData->call_time_scheduling;
$leadid = $rowData->lead_id;



// Print the value of $userEmail
echo $userEmail;

// Add the address to the mail without quotes around variable names
$mail->addAddress($userEmail, $userFullName);

            // Email content
            $mail->isHTML(true);
            $mail->Subject = 'Remainder Today';
				$mail->Body='<html>
					<body style="background-color:#ddd; padding:0; margin:0; font-family:Verdana, Geneva, sans-serif; font-size:14px;">
						<section align="center">
							<div style="width:100%; max-width:710px; margin:auto; background:#fff; text-align: left;">
								<table style="width:100%;" border="0" cellspacing="0">
									<tr style="background-color:#cd5547;">
										<td style="width:30%; padding:10px 0 10px 35px;">
												<img style="margin-top:0; width:200px; height:68px;" src="https://rishtasite.com/assets/images/logo-black.png">
										</td>
										<td style="width:70%; padding:10px 35px 10px 0 ;">
											<p style="text-align:right; color:#fff;">        
												<strong style="font-size:20px;">24x7 Support</strong><br/>
												+91 9054811166<br/>
							            	<span style="color:#fff!important">karan.singh@rishtadepot.com</span>
											</p>
										</td>
									</tr>
								</table>
								<div style="margin-bottom:30px;padding: 40px 30px 10px;">
									<p>
									Hello '.$userFullName.' Today Follow up <br/>Lead ID: '.$leadid.' <br/>Lead Name: '.$contact_name.' <br/>Lead Status: '.$disposition.' <br/>Call Scheduling: '.$call_scheduling.'<br/>
									  Call Time Scheduling: '.$call_time_scheduling.'  <br/> 
									'.$html.'
									</p>
								</div>

							
							</div>    
						</section>	
					</body>
				</html>';
						
				//		 Set content-type header for sending HTML email 
						
                 //       $headers = "MIME-Version: 1.0" . "\r\n"; 
                   //    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 

                     //  mail($mailTo,$mailSubject,$mailBody,$headers);
                     
                     
                     // Send the email
if ($mail->send()) {
echo 'email send';
} else {
    echo 'Error: ' . $mail->ErrorInfo;
}
            }
?>
