Send email on status change
Posted: 2020-10-30 20:48
Hi, I’m using the below code on most of my little project to send an email when the checkbox is ticked. I have a Status field (dropdown, not lookup) with two option: Complete;;Incomplete. I want to send an email when option ‘Complete’ is selected in the Status field instead of using checkbox method. Could someone possibly help me to change the below code to achieve this? Presuming the table name is ‘my_table_name’ with field ‘report_status’ that has options: Complete;;Incomplete . Thank You
Code: Select all
// ******** Send email if checkbox is checked *********
$recipient = $data['email'];
$CC = "";
$sendemail = sqlValue("select emailadvice from my_table_name where id='{$data['selectedID']}'");
$userEmail = sqlValue("select email from membership_users where memberID='".getLoggedMemberID()."'");
if ($sendemail != 0) {
$resetMail = @mail(
// To
"$recipient, $userEmail",
// Subject
"Incident Report Submitted by {$memberInfo['custom'][0]}",
// Content
"Incident Report Submitted by {$memberInfo['custom'][0]}. \n" .
" \n" .
"For full report details please go to XXXXXXX and select record number: {$data['id']}. \n" .
"================================================ \n" .
"DO NOT REPLY TO THIS EMAIL. This report is generated by XXXXX",
// From
"From: [email protected]"
);
// then update the send email checkbox back to default of 0
if (resetMail) {
sql("update my_table_name set emailadvice=0 where id='{$data['selectedID']}'", $abc);
}
}
// ******** End send email if checkbox is checked *******
return TRUE;
}