Index of /home/htscrtms/newcrm.htshah.com/hslider
<?php
ob_start();
include('lib/db_connect.php');
include('lib/auth.php');
require 'lib/phpmailer/PHPMailer.php';
require 'lib/phpmailer/SMTP.php';
require 'lib/phpmailer/Exception.php';
require 'lib/vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
date_default_timezone_set("Asia/Kolkata");
$date = date('d-m-Y');
$client_id = $_REQUEST['client_id'] ?? '';
if (empty($client_id)) {
die("Client ID is required.");
}
$selc = "SELECT * FROM `tabl_client` WHERE id='$client_id'";
$qryc = mysqli_query($con, $selc) or die(mysqli_error($con));
$rowc = mysqli_fetch_array($qryc);
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle("Import Report");
$headers = ["Sr.", "HTSHAH Job", "Client", "Product", "FCL / LCL", "Inv. No. & Supplier", "Eta", "Goods Registration Date", "Cont Arrived / Scan", "Duty", "Customs Complete / OCC Available", "Org. docs. recd date", "Delivery Prom. Date", "Client Remarks", "Cont. bond recd date", "Empty letter valid dt", "Remarks"];
$sheet->fromArray($headers, NULL, 'A1');
$rowNum = 2;
$count = 1;
$sel = "SELECT * FROM `tabl_importbooking` WHERE DELFLAG='N' AND STATUS='0' AND client_id='$client_id' ORDER BY id DESC";
$qry = mysqli_query($con, $sel) or die(mysqli_error($con));
while ($row = mysqli_fetch_array($qry)) {
$sheet->fromArray([
$count++,
$row['htshah_no'],
$rowc['userName'],
$row['product'],
$row['fcl_Lcl'],
$row['invoice'],
$row['eta'],
$row['igm'],
$row['av'],
$row['duty'],
$row['free_Detention'],
$row['org_Doc_Dt'],
$row['del_Pro_Dt'],
$row['client_Remark'],
$row['cont_Bond_Dt'],
$row['emptyLetter_Val_Dt'],
$row['remark']
], NULL, 'A' . $rowNum++);
}
$filename = 'importbookingreport.xlsx';
$writer = new Xlsx($spreadsheet);
$writer->save($filename);
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'mail.htshah.com';
$mail->SMTPAuth = true;
$mail->Username = '_mainaccount@htshah.com';
$mail->Password = 'rQ9LhUA5R9gp8q3wTW4d';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
$mail->Port = 465;
$mail->setFrom('cse@htshah.com', 'HTSHAH Reports');
//$mail->addAddress("hackertechv21@gmail.com");
$emails = explode(',', $rowc["email"]);
foreach ($emails as $email) {
$email = trim($email);
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$mail->addAddress($email);
}
}
// Recipient email
$mail->addCC('htshahcomum@hotmail.com'); // Add CC if needed
// $mail->addBCC('bcc@example.com'); // Add BCC if needed
$mail->Subject = "Import Report as of " . $date;
$mail->Body = "Please find the attached Import Report.";
$mail->AltBody = "Please find the attached Import Report.";
$mail->addAttachment($filename);
$mail->send();
echo '<script>alert("Mail sent successfully.");window.location.href="importBookingReport.php";</script>';
} catch (Exception $e) {
echo "Mail could not be sent. PHPMailer Error: {$mail->ErrorInfo}";
}
?>