Don't know if this will help you but I managed to integrate a relatively straight forward (and unobtrusive) option to email a selected recipient(s) on "Saving" a record with the addition of a check box and a tablename_after_update hook. If the checkbox is checked - an email is sent when the record is Updated. If not - no email sent. Works a treat and very simple to setup.
For purposes of example, I'll use table name of "jobs". Primary key is "id". In this example, all fields mentioned are within the jobs table.
First I add a field for the email address you want to send to. This way, you can change it whenever you want to. Field name "emailto". You can also grab the email address from some other field/table/membership record but for this example, I'll keep it simple.
I add a checkbox (tiny int - field name "emailadvice") with a default value of 0
Then add a simple hook that generates the email after update and then also resets the checkbox value to 0
function jobs_after_update($data, $memberInfo, &$args){
// ******** Send email if checkbox is checked *********
$recipient = $data['emailto'];
$CC = "";
$sendemail=sqlValue("select emailadvice from jobs where id='{$data['selectedID']}'");
if($sendemail!=0){
$resetMail=@mail(
// To
$recipient,
// Subject
"A database record has been updated",
// Content
"Just add whatever content and fields you want to the email.\n" .
"Account No.: {$data['contract']}\n" .
"Name: {$data['name']}\n" .
"Our Job No.: {$data['id']}\n" .
"Current Job Status: {$data['status']}\n" .
"Please login to your account at
http://www.yourdomain.com to view all of the details",
// From
"From:
[email protected]"
);
// then update the send email checkbox back to default of 0
if(resetMail){
sql("update jobs set emailadvice=0 where ourref='{$data['selectedID']}'", $abc);
}
}
// ******** End send email if checkbox is checked *******
The checkbox will be set back to default value of 0 (unchecked) after the record is updated and the email is sent. Works well for me and my case. Hope it works for you too.