<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'jobs/src/Exception.php';
require 'jobs/src/PHPMailer.php';
require 'jobs/src/SMTP.php';
include 'inc/db_config.php'; 
ini_set('display_errors', 0);
if (isset($_POST['tmp_b_id'])) {
	 $temp_id = $_POST['tmp_b_id'];
	 $email_content = $_POST['email'];
     


mysqli_query($connection,'SET CHARACTER SET utf8');
mysqli_query($connection,"SET SESSION collation_connection ='utf8_general_ci'");
	 $bookingtSQL = mysqli_query($connection, "SELECT v1.*,v2.title as ref_name from (SELECT t1.*,t2.name ev_type FROM `bookings` as t1 left join booking_types as t2 on t1.event_type=t2.id where t1.id='$temp_id') as v1 left join ref as v2 on v1.ref=v2.id ");
$list= mysqli_fetch_object($bookingtSQL);
									
                                    $idn = $list->id;
									 $name = $list->name;
									$cell_1 = $list->cell_1;
									$cell_2 = $list->cell_2;
									 $email = $list->email;
									 $ev_type = $list->ev_type;
									 
								    $client_email=$list->email;
									 
									 
									  $fb= $list->fb;  
									    $ref= $list->ref_name;  
										 $groom_name= $list->groom_name;  
										  $groom_fb= $list->groom_fb;  
										   $groom_email= $list->groom_email;  
										   $groom_mobile= $list->groom_mobile;
										   
										    $groom_father= $list->groom_father;  if($groom_father=="checked"){$groom_father="yes";}
											 $groom_mother= $list->groom_mother;  if($groom_mother=="checked"){$groom_mother="yes";}
											  $groom_brother= $list->groom_brother;  if($groom_brother=="checked"){$groom_brother="yes";}
											   $groom_sister= $list->groom_sister;  if($groom_sister=="checked"){$groom_sister="yes";}
											   
											   $bride_name= $list->bride_name;  
											    $bride_fb= $list->bride_fb;  
										   $bride_email= $list->bride_email;
										    $bride_mobile= $list->bride_mobile;
										    $bride_father= $list->bride_father;  if($bride_father=="checked"){$bride_father="yes";}
											 $bride_mother= $list->bride_mother;  if($bride_mother=="checked"){$bride_mother="yes";}
											  $bride_brother= $list->bride_brother;  if($bride_brother=="checked"){$bride_brother="yes";}
											  $bride_sister= $list->bride_sister; if($bride_sister=="checked"){$bride_sister="yes";}


                               
$booking_id = $list->booking_id;
$booking_name = $list->booking_name;
$booking_type=$list->event_type;
$additional_notes = $list->additional_notes;
$vas = $list->vas;
$pkg_charge = $list->pkg_charge;
$discount = $list->discount;
$total_charge = $list->total_charge;		
$advance = $list->advance;								 
$due = $list->due;	
$added_at = $list->added_at;	
$updated_at = $list->updated_at;

$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='password' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
									
$em_password = $settingsSQL->value;


$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='sender_email' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
									
$sender_email = $settingsSQL->value;


$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='smtp_host' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
									
$smtp_host = $settingsSQL->value;


$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='ssl_port' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
									
$ssl_port = $settingsSQL->value;	
}
include("file.php");



// Load Composer's autoloader


// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = 2;                                       // Enable verbose debug output
    $mail->isSMTP();                                            // Set mailer to use SMTP
    $mail->Host       = $smtp_host;  // Specify main and backup SMTP servers
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = $sender_email;                     // SMTP username
    $mail->Password   = $em_password;                               // SMTP password
    $mail->SMTPSecure = 'ssl';                                  // Enable TLS encryption, `ssl` also accepted
    $mail->Port       = $ssl_port;                                    // TCP port to connect to


    //Recipients
    $mail->setFrom('backup@bgx.apm.mybluehost.me', 'WD CRM');
    $mail->addAddress($client_email, 'z');     // Add a recipient
   
    

    // Attachments
  //  $mail->addAttachment($FileName_as);         // Add attachments
	$mail->addAttachment($filename);         // Add attachments
	//$mail->addAttachment($FileName_bk);  
   // $mail->addAttachment($FileName_py);  
	//$mail->addAttachment('db_backup/db-backup-'.date("Ymd", time()).'.sql.gz'); 
	
	
    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Your Booking Confirmation : Wedding Diary';
    $mail->Body    = $email_content;
    $mail->AltBody = $email_content;

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

?>