<?php

error_reporting(E_ALL);
ini_set('display_errors',1);

require( './wp-load.php' );
date_default_timezone_set('Asia/Singapore');


// Hooking up functions to the correct WordPress filters 
add_filter( 'wp_mail_from', 'change_default_sender_email' );
add_filter( 'wp_mail_from_name', 'change_default_sender_name' );


$querystr3 = "SELECT * FROM insurance_payment WHERE insurance_year = '2025' AND email_sent = 1 AND paid = 1;";
$listing = $wpdb->get_results($querystr3, OBJECT);

$subject = 'Thank you for purchasing/renewing the Professional Indemnity. ';

foreach($listing as $p)
{
	$to = $p->email;

	
	$body = "
	<p>
	Dear SRP member,</p>
<p>
<strong>Here are the details of your payment:</strong>

</p>
<p>
Payment Amount: $".$p->amount."<br>
Transaction ID: ".$p->transaction_no."<br>
Payment Date: ".date('d/m/Y h:i A',strtotime($p->payment_datetime))."<br>
</p>
<p>
We have received your payment. You may check in your Dashboard in January for the Professional Indemnity Certificate. It will be uploaded to your account after all applications have been processed. 

</p>
<p>
Should you have any queries, please feel free to write to our Secretariat at secretariat@singaporepsychologicalsociety.org
</p>
<p>
<strong>Regards,</strong><br>
Singapore Psychological Society
</p>
<p>
8 Eu Tong Sen Street #18-81 The Central Singapore 059818 | Email: <a href='mailto:secretariat@singaporepsychologicalsociety.org;'>secretariat@singaporepsychologicalsociety.org</a>
</p>


	";
	$headers = array('Content-Type: text/html; charset=UTF-8');

	if($to != '')
		wp_mail( $to, $subject, $body, $headers );
	
	
	$datetime_email_sent = date('Y-m-d H:i:s');

	$update_q = "UPDATE insurance_payment SET datetime_email_sent = '".$datetime_email_sent."', email_sent = 1 WHERE id = ".$p->id;
	
	$wpdb->query($update_q);
	
}

print 'SENT';