Page 1 of 1

Send email on status change

Posted: 2020-10-30 20:48
by aarlauskas
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;
	}

Re: Send email on status change

Posted: 2020-10-30 21:43
by pbottcher
Hi,

just retrieve the status field instead of the emailadvice .

then use e.g.

Code: Select all

If ($sendmail == 'Complete')

Re: Send email on status change

Posted: 2020-10-31 08:22
by aarlauskas
Hi, doesn't seem to work this way, unless I'm missing something. Any chance you could copy/paste my complete code here with the change that you think should work? Thanks

Re: Send email on status change

Posted: 2020-10-31 15:30
by pbottcher
Can you post the code you tried?

Re: Send email on status change

Posted: 2020-10-31 19:39
by aarlauskas
Ok I found the error, small typo in your line. I was copying your line as you sent 'If ($sendmail == 'Complete')' . but just noticed in your line you put $sendmail instead of $sendemail. Great Success man :D All working, Thank You!