<?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 cert_email_sent = 0 AND file != '' AND paid = 1;";
$listing = $wpdb->get_results($querystr3, OBJECT);


$subject = 'Professional Indemnity Insurance - Certificate Download';

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

	
	$body = "
	<p>
	Dear SRP member,</p>
<p>
Your renewed insurance certificate is now available for download.
</p>
<p>
To access your certificate, please follow these simple steps:
</p>
<p>
1) Visit our website: https://singaporepsychologicalsociety.org/login/<br>
Log in to your account using your credentials.
</p>
<p>
2) Navigate to the dashboard page, Locate Professional Indemnity Insurance section through the left side menu.
</p>
<p>
3) Locate and download your updated certificate.
</p>

<p>
If you encounter any difficulties, reach out to us 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_cert_email_sent = date('Y-m-d H:i:s');

	$update_q = "UPDATE insurance_payment SET datetime_cert_email_sent = '".$datetime_cert_email_sent."', cert_email_sent = 1 WHERE  insurance_year = 2025 AND id = ".$p->id;
	
	$wpdb->query($update_q);
	
}

print 'SENT';