I've pinched a lot of code from other places and managed to write (bodge) the following. Placing the file in the 'income_created' event folder, means it fires the thank_you email when marked as paid in the back-end.
<?php
//Ensure this file has been reached through a valid entry point (not always necessary eg. for class files, but included on every file to be safe!)
(defined('_VALID_MOS') || defined('_JEXEC') || defined('NBILL_VALID_NBF')) or die('Access Denied.');
$nb_database = nbf_cms::$interop->database;
$trans_id = $params['id'];
//Query used to match up the transaction ID to the primary email address
$sql="SELECT c.first_name, c.last_name, CONCAT_WS(' ',c. first_name,c. last_name) as name, c.email_address, c.user_id , e.id as client_id, d.document_no as record_name, d.id as record FROM `#__nbill_contact` c INNER JOIN `#__nbill_entity` e ON e.primary_contact_id = c.id INNER JOIN `#__nbill_document` d ON e.id = d.entity_id INNER JOIN `#__nbill_transaction` t ON t.document_ids = d.id WHERE t.id = '" . nbf_common::get_param($params,'id') . "'";
$nb_database->setQuery($sql);
$rows = $nb_database->loadObjectList();
if(count($rows)<1){
return;
}
$row=$rows[0];
//Define the client specific variables
$email_address = $row->email_address;
$email_body = "";
$client_id = $row->client_id;
$orig_record_id = $row->record;
$orig_record_name = $row->record_name;
$contact_name = $row->name;
//Initialise
$admin_email = "accounts@example.com"; //Update with the admin address
$admin_name = "Vendor or Company"; //Update with your own
$email_subject = "Payment Received for " . $orig_record_name . " - Thank you.";
$email_body .= "<body><html>";
$email_body .= "<p>Dear " . $contact_name . "</p>\n\n";
$email_body .= "<p>Your recent payment for the invoice " . $orig_record_name . " has been received.</p><p>Thank you!</p>\n";
$email_body .= "<p>Best Regards,</p>";
$email_body .= nbf_cms::$interop->site_name;
$email_body .= "</body></html>";
$html = true;
$attachments = null;
//Send the HTML email
$mailsent = nbf_cms::$interop->send_email($admin_email, $admin_name, $email_address, $email_subject, $email_body, $html ? 1 : 0, null, null, $attachments);
$status = ""; //Empty string = unknown error (OK = ok, other = other error message)
//Check to make sure the mail is sent
if (!$mailsent)
{
$failure = true;
$status = nbf_globals::$message;
}
else
{
$status = "OK";
}
//Insert entry in email log
$sql = "INSERT INTO #__nbill_email_log (`type`, `entity_id`, `document_id`, `from`, `to`, `timestamp`, `status`, `subject`, `message`, `html`) VALUES ('IN', " . intval($client_id) . ", " . intval($orig_record_id) . ", '" . $admin_email . "', '" . $email_address . "', " . nbf_common::nb_time() . ", '" . $nb_database->getEscaped($status) . "', '" . $nb_database->getEscaped($email_subject) . "', '" . $nb_database->getEscaped($email_body) . "', " . ($html ? 1 : 0) . ")";
$nb_database->setQuery($sql);
$nb_database->query();
?>
Hope someone might find this useful - and thanks again for the helpful replies.