SMTPDebug = 2; //enable debugging if failure $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = "mail.ohctech.com"; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = "info@ohctech.com"; // SMTP username $mail->Password = "Tikora@1234"; // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port ="587"; // TCP port to connect to $mail->isHTML(true); // Sender info $mail->setFrom("info@ohctech.com", 'OHC'); $mail->addReplyTo("info@ohctech.com", 'OHC'); $from="info@ohctech.com"; */ $from = getConfigKey('email_username'); $headers = "From: OHCTECH\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $mail_content = "Welcome to OHC. Your OTP to verify Your Email ID is"; $toList = str_replace(' ', ',', $toList); $toList = str_replace(';', ',', $toList); $ccList = str_replace(' ', ',', $ccList); $ccList = str_replace(';', ',', $ccList); $toList_arr = preg_split("/\,/", $toList); $ccList_arr = preg_split("/\,/", $ccList); try { $mail->isSMTP(); // Set mailer to use SMTP $mail->SMTPDebug = 2; $mail->Host = getConfigKey('email_host'); // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = getConfigKey('email_username'); // SMTP username $mail->Password = getConfigKey('email_password'); // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = getConfigKey('email_port'); // TCP port to connect to $mail->isHTML(true); // Sender info $mail->setFrom(getConfigKey('email_username'), 'OHC'); $mail->addReplyTo(getConfigKey('email_username'), 'OHC'); foreach ($toList_arr as $toaddr) { $mail->addAddress($toaddr); } foreach ($ccList_arr as $ccaddr) { $mail->addCC($ccaddr); } $style = ""; $mail->Subject = $subject; $mail->Body = $style . $messageBody . $remarks; error_log("email_sender done settings"); if (!$mail->send()) { // echo "Message could not be sent. Mailer Error: " . $mail->ErrorInfo; error_log('Message could not be sent. Mailer Error: ' . $mail->ErrorInfo); } else { // echo "Message has been sent"; error_log("Message has been sent"); } error_log('Message has been sent.'); } catch (phpmailerException $e) { echo $e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { echo $e->getMessage(); //Boring error messages from anything else! } } $currentDate = date('Y-m-d'); $sql = "select * from batch_status where run_date = '$currentDate'"; error_log("query to get batch mail data " . $sql); $result = mysqli_query($conn, $sql); while ($row = mysqli_fetch_assoc($result)) { error_log("data " . $row); if (trim($row['run_date']) != '0000-00-00' && trim($row['run_date']) != null) { send_batch_mail($row); } else { error_log("No Record Found For Date " . $currentDate); } } function send_batch_mail($row) { $issues = $row['error']; $updates = $row['update_count']; $inserts = $row['insert_count']; $run_date = date('d-m-Y', strtotime($row['run_date'])); $status = $row['status']; $to_list = getBatchToList(); $subject = "Patient Batch Update Details"; $message = "Patient Batch Update Summary - " . $run_date . "\n\n"; $message .= "Total Update Records: " . $updates . "\n\n"; $message .= "Total Insert Records: " . $inserts . "\n\n"; $message .= "Status: " . $status . "\n\n"; if (!empty($issues)) { $message .= "Issues:\n"; $message .= $issues . "\n"; } error_log("To list " . print_r($to_list, true)); if ($to_list) { if (send_mail($to_list, '', $subject, $message, '')) { error_log("Batch email sent successfully to " . $to_list); } else { error_log("Error sending batch email to " . $to_list); } } else { error_log("To list is empty to send mail " . $to_list); } } function getBatchToList() { $sql = "select value from config where key_name ='to_list'"; $result = mysqli_query($GLOBALS['conn'], $sql); $row = mysqli_fetch_assoc($result); return $row['value']; }