<?php require_once('../admin/includes/connection.php');
//$_REQUEST['payment_status']="Completed";
$_REQUEST['custom']="bfc9cf13f2";
$req_dump = print_r( $_REQUEST, true );
$fp = file_put_contents( 'request.log', $req_dump );

require 'mailer/vendor/autoload.php';

require 'mailer/src/PHPMailer.php';
require 'mailer/src/SMTP.php';
require 'mailer/src/Exception.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;

//////////////////////////////////

if(empty($_REQUEST['payment_status'])){
$mail_From = "From:system@elanoaks.co.uk";
$mail_To = "keith@daso-interactive.co.uk";
$mail_Subject = "ELANOAKS IPN ACCESS";
$emailtext="Unauthorised Access to Elan Oaks Payment Script"."\n"."IP : ".$_SERVER['REMOTE_ADDR']."\n"."Referer : ".$_SERVER['HTTP_REFERER']."\n"."Query 

String : ".$_SERVER['QUERY_STRING']."\n"."User Agent : ".$_SERVER['HTTP_USER_AGENT']."\n"."Remote Host : ".$_SERVER['REMOTE_HOST'];
mail($mail_To, $mail_Subject, $emailtext, $mail_From);
echo "Hack Attempt.. I'm Telling!! <br> Your IP is : ".$_SERVER['REMOTE_ADDR'];
}


else{
########################################### COMPLETE ###########################################
if ($_REQUEST['payment_status'] == "Completed") {
function settings($type){
$settingCall=mysqli_query($GLOBALS['bookingCon'],"SELECT * FROM `booking_settings` WHERE `id`='1'")or die(mysqli_error($GLOBALS['bookingCon']));
$settings=mysqli_fetch_array($settingCall);
if($type=="bookingMode"){return $settings['bookingMode'];}
if($type=="cc"){return $settings['cc'];}
if($type=="o16"){return $settings['o16'];} 
if($type=="u16"){return $settings['u16'];}
if($type=="pets"){return $settings['pets'];}  
if($type=="vehicles"){return $settings['vehicles'];} 
if($type=="days"){return $settings['days'];}
if($type=="party_details"){return $settings['party_details'];}
if($type=="vehicle_details"){return $settings['vehicle_details'];}
if($type=="checkin"){return $settings['checkin'];}
if($type=="checkout"){return $settings['checkout'];}
if($type=="email_access_codes"){return 0;}
}

$BookingUpdate=mysqli_query($GLOBALS['bookingCon'],"UPDATE `booking_reservation` SET `payment_status`='1',`tx_code`='".$_REQUEST['txn_id']."',`balance`='0.00' WHERE `unique_id`='".$_REQUEST['custom']."'")or die('2'.mysqli_error($GLOBALS['bookingCon']));

$accessCall=mysqli_query($GLOBALS['bookingCon'],"SELECT * FROM `booking_codes` WHERE `id`='1'")or die(mysqli_error($GLOBALS['bookingCon']));
$accessData=mysqli_fetch_array($accessCall);

$reservation=mysqli_query($GLOBALS['bookingCon'],"SELECT * FROM `booking_reservation` WHERE `unique_id`='".$_REQUEST['custom']."'")or die("1".mysqli_error($GLOBALS['bookingCon']));
$reservation_details=mysqli_fetch_array($reservation);
$dateFrom= new DateTime($reservation_details['date_from']);
$dateTo= new DateTime($reservation_details['date_to']);


$booking=mysqli_query($GLOBALS['bookingCon'],"SELECT * FROM `booking_details` WHERE `booking_id`='".$reservation_details['id']."'")or die(mysqli_error($GLOBALS['bookingCon']));
$booking_details=mysqli_fetch_array($booking);

$client=mysqli_query($GLOBALS['bookingCon'],"SELECT * FROM `booking_client` WHERE `id`='".$reservation_details['client_id']."'")or die(mysqli_error($GLOBALS['bookingCon']));
$client_details=mysqli_fetch_array($client);

$unit=mysqli_query($GLOBALS['bookingCon'],"SELECT * FROM `booking_units` WHERE `id`='".$booking_details['unit_id']."'")or die(mysqli_error($GLOBALS['bookingCon']));
$unit_details=mysqli_fetch_array($unit);

$accessCall=mysqli_query($GLOBALS['con'],"SELECT * FROM `booking_codes` WHERE `id`='1'")or die(mysqli_error($GLOBALS['bookingCon']));
$accessData=mysqli_fetch_array($accessCall);

$fromMonth=$dateFrom->format('m');
if($fromMonth=="01"){$accesCode="<b>".$accessData['access_jan']."</b> for January";}
if($fromMonth=="02"){$accesCode="<b>".$accessData['access_feb']."</b> for Fenruary";}
if($fromMonth=="03"){$accesCode="<b>".$accessData['access_mar']."</b> for March";}
if($fromMonth=="04"){$accesCode="<b>".$accessData['access_apr']."</b> for April";}
if($fromMonth=="05"){$accesCode="<b>".$accessData['access_may']."</b> for May";}
if($fromMonth=="06"){$accesCode="<b>".$accessData['access_jun']."</b> for June";}
if($fromMonth=="07"){$accesCode="<b>".$accessData['access_jul']."</b> for July";}
if($fromMonth=="08"){$accesCode="<b>".$accessData['access_aug']."</b> for August";}
if($fromMonth=="09"){$accesCode="<b>".$accessData['access_sep']."</b> for September";}
if($fromMonth=="10"){$accesCode="<b>".$accessData['access_oct']."</b> for October";}
if($fromMonth=="11"){$accesCode="<b>".$accessData['access_nov']."</b> for November";}
if($fromMonth=="12"){$accesCode="<b>".$accessData['access_dec']."</b> for December";}
$toMonth=$dateTo->format('m');
if($toMonth=="01"){$secondCode=" and <b>".$accessData['access_jan']."</b> for January";}
if($toMonth=="02"){$secondCode=" and <b>".$accessData['access_feb']."</b> for Fenruary";}
if($toMonth=="03"){$secondCode=" and <b>".$accessData['access_mar']."</b> for March";}
if($toMonth=="04"){$secondCode=" and <b>".$accessData['access_apr']."</b> for April";}
if($toMonth=="05"){$secondCode=" and <b>".$accessData['access_may']."</b> for May";}
if($toMonth=="06"){$secondCode=" and <b>".$accessData['access_jun']."</b> for June";}
if($toMonth=="07"){$secondCode=" and <b>".$accessData['access_jul']."</b> for July";}
if($toMonth=="08"){$secondCode=" and <b>".$accessData['access_aug']."</b> for August";}
if($toMonth=="09"){$secondCode=" and <b>".$accessData['access_sep']."</b> for September";}
if($toMonth=="10"){$secondCode=" and <b>".$accessData['access_oct']."</b> for October";}
if($toMonth=="11"){$secondCode=" and <b>".$accessData['access_nov']."</b> for November";}
if($toMonth=="12"){$secondCode=" and <b>".$accessData['access_dec']."</b> for December";}
//TESTING
if($fromMonth!=$toMonth){$accesCode=$accesCode.$secondCode;}

//TESTING

include('../booking/emailSystem/email_header.php');

include('../booking/emailSystem/email_template-confirmation.php');
$subject="BOOKING-".$reservation_details['unique_id']."- Your Booking Confirmation";


include('../booking/emailSystem/email_footer.php');

$email=str_replace('[BODY-COLOUR]','#cccccc',$email);
$email=str_replace('[HEADER-COLOUR]','#333333',$email);
$email=str_replace('[THEME-COLOUR]','#a07023',$email);

$email=str_replace('[COMPANY-LOGO]','emailImages/logo_1_thumb.png?'.rand(),$email);
$email=str_replace('[COMPANY_NAME]','Elan Oaks',$email);
$email=str_replace('[COMPANY_ADDRESS_1]','Elan Valley',$email);
$email=str_replace('[COMPANY_ADDRESS_2]','Rhayader',$email);
$email=str_replace('[COMPANY_POSTCODE]','LD6 5HP',$email);
$email=str_replace('[COMPANY_PHONE]','01597 810326',$email);

$email=str_replace('[LOCATE_URL]','https://g.page/elanoaks?share',$email);
$email=str_replace('[BGIMAGE1]','emailImages/panel.jpg?'.rand(),$email);
$email=str_replace('[BGIMAGE2]','emailImages/map-bg.png?'.rand(),$email);
$email=str_replace('[BGIMAGE3]','emailImages/panel_small.jpg?'.rand(),$email);
$email=str_replace('[MAP-PIN]','emailImages/map-pin.png?'.rand(),$email);
$email=str_replace('[MAP-PIN-SMALL]','emailImages/map-pin-small.png?'.rand(),$email);

$email=str_replace('[DATA-URL]','https://elanoaks.co.uk/booking',$email);
$email=str_replace('[DATA-SITE]',$unit_details['name'],$email);
$email=str_replace('[DATA-DATEIN]',$dateFrom->format('d-m-Y'),$email);
$email=str_replace('[DATA-DATEOUT]',$dateTo->format('d-m-Y'),$email);
$email=str_replace('[DATA-ADULTCOUNT]',$booking_details['adults'],$email);
$email=str_replace('[DATA-CHILDCOUNT]',$booking_details['children'],$email);
$email=str_replace('[DATA-PETCOUNT]',$booking_details['pets'],$email);
$email=str_replace('[DATA-VEHICLES]',$booking_details['vehicles'],$email);
$email=str_replace('[DATA-PRICE]',number_format($booking_details['price'],2),$email);
$email=str_replace('[DATA-DEPOSIT]',number_format($reservation_details['deposit'],2),$email);
$email=str_replace('[DATA-NAME]',$client_details['first_name'].' '.$client_details['last_name'],$email);
$email=str_replace('[DATA-ADDRESS1]',$client_details['address_1'],$email);
$email=str_replace('[DATA-ADDRESS2]',$client_details['address_2'],$email);
$email=str_replace('[DATA-TOWN]',$client_details['town'],$email);
$email=str_replace('[DATA-COUNTY]',$client_details['county'],$email);
$email=str_replace('[DATA-POSTCODE]',$client_details['post_code'],$email);
$email=str_replace('[DATA-TEL]',$client_details['phone'],$email);
$email=str_replace('[DATA-REG]',$client_details['reg'],$email);
$email=str_replace('[DATA-CODETEXT]','The codes for your stay are as follows',$email);
$email=str_replace('[DATA-ACCESS]',$accesCode,$email);
$email=str_replace('[DATA-SHOWER]',$accessData['access_shower'],$email);
$email=str_replace('[DATA-WIFI]',$accessData['access_wifi'],$email);
$email=str_replace('[DATA-YEAR]',date('Y'),$email);
$email=str_replace('[DATA-CHECKIN]',settings('checkin'),$email);
$email=str_replace('[DATA-CHECKOUT]',settings['checkout'],$email);
$email=str_replace('[DATA-QR]','/invoices/'.$_REQUEST['bookingId'].'.png',$email);

$combine=$email;

$mail = new PHPMailer(true);

try {
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->SMTPAuth = true;
$mail->Username = 'contact@elanoaks.co.uk';
$mail->Password = 'Russell19!';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

$mail->setFrom('contact@elanoaks.co.uk', 'Elan Oaks');

$mail->addAddress($client_details['email'], $booking_details['name']);
$mail->addReplyTo('contact@elanoaks.co.uk', 'Elan Oaks');
$mail->addBcc("keith@daso-interactive.co.uk", "Keith Fielding");

//$mail->addAttachment('image.jpg');
$mail->CharSet = 'UTF-8';
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body    = $combine;
$mail->AltBody = $combine;
$mail->SMTPDebug = SMTP::DEBUG_SERVER;

$mail->SMTPOptions = array(
       'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        );  

$mail->send();
$ml = file_put_contents( 'mailer.log', $combine );
//echo $combine;
//echo 'success'.RESPONSE;

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


}?>

<?php if($_REQUEST['payment_status']!="Completed"){?>


<h2>There was an error!</h2>
<?php }

}?>

hi
<?php echo $client_details['email']?>