Email Sending issue

I am running the latest 2020vMy issue is that I am trying to edit the contents of an email sent when a record is added.

As of right now this is the content of the email that gets sent:Record status changed as follows:
Table: ChangMGMT
Key value: 8
Action: Inserted

Under the Server Events->Table-Specific->Common->Email_Sending I added the following code:function Email_Sending($email, &$args) {

if (CurrentPageID() == "add") { // If Add page
	 
	$Email->Subject = "Network Change Management System (New change expecting approval)"; // Change subject 
	$Email->Format = "HTML";
	$Email->Content = " "; 
	$Email->Content .= "Hello,<br>&nbsp;<br/><p>A new change has been added to the NCMS (Network Change Managment System.)</p>";
	$Email->Content = "<br><p><Please, login and approve so the change can be implemented!</p>";
}
return TRUE;

}

BUT I keep receiving the email default format. Why isn’t the change taking effect?Can anyone help me with this?

napiedra wrote:
function Email_Sending($email, &$args) {

The argument is $email, not $Email.

I corrected that and I am still experiencing the same issue.Here is my new crypt:// Email Sending event
function Email_Sending(&$email, &$Args) {// add
if (CurrentPageID() == “add”) {
$email->Subject = “A new Change has been submitted!”;
$email->Content = “Hello network team,”;
$email->Content .= “

Please, login into the system and approve so the change can be implemented!”;
$email->Content .= “

\n Change ID: ” . $Args[“rsnew”][“ChangeID”].“”;
$email->Content .= “

\n Change Title: ” . $Args[“rsnew”][“Change_Title”].“”;
$email->Content .= “

Network Change Requested by: ” . CurrentUserName().“”;
}// edit
if (CurrentPageID() == “edit”) {
$email->Subject = “Model Database - Editace záznamu v tabulky fotky”;
$email->Content = “Editace záznamu v tabulky fotky”;
$email->Content .= “

\n Change ID: ” . $Args[“rsnew”][“ChangeID”].“”;
$email->Content .= “

\n Change Title: ” . $Args[“rsnew”][“Change_Title”].“”;
$email->Content .= “

Network Change approved by: ” . CurrentUserName().“”;
}//var_dump($email); var_dump($Args); exit();
return TRUE;
}Is there another setting somewhere else that I am not aware of? My emails continue to be the default as follows:Record status changed as follows:
Table: ChangMGMT
Key value: 9
Action: Updated

Never mind… it works now. I was not updating the files on the correct server. The right scrip is now working as posted.

This has been working great. However, I would like to reduce the amount of email we get. I wish there was a way that, under the “edit” clause, would send the email only if certain record is updated.

For example, I have a record in my table called “Aproval”. I only want to receive email if this record gets changed. How can this be acomplished?

Here is my script:

function Email_Sending(&$email, &$Args) {

// edit
if (CurrentPageID() == “edit”) {
$email->Subject = “Network Change Status has changed!”;
$email->Content = “

Hello network team,

”;
$email->Content .= “

This email is to let you know that your network change request status has changed.”;
$email->Content .= “

\n Change ID: ” . $Args[“rsold”][“ChangeID”].“”;
$email->Content .= “

\n Change Title: ” . $Args[“rsnew”][“Change_Title”].“”;
$email->Content .= “

\n Change Description: ” . $Args[“rsnew”][“Description”].“”;
$email->Content .= “

\n To be implemented by: ” . $Args[“rsnew”][“Scheduled_Datetime”].“”;
$email->Content .= “

Network Change reviewed by: ” . CurrentUserName().“”;
$email->Content .= “

Thanks!”;
}

//var_dump($email); var_dump($Args); exit();
return TRUE;
}

Change this:
if (CurrentPageID() == “edit”) {

to:
if (CurrentPageID() == “edit” && $Args[“rsnew”][“MyStatus”] == “Aproval”) { // adjust “MyStatus” to your actual related field name

I tried that with the following and apparently there is a syntax error as the page is not showing.

Here is how I adjusted:

if (CurrentPageID() == “edit” && $Args[“rsnew”][“Approval”] < 0) because Approval can be 0 (pending), 1 (reviewed) and 2 (approved). I would like to send emails when the Approval changes to anything other than 0.

Then this code:
if (CurrentPageID() == “edit” && $Args[“rsnew”][“Approval”] < 0)

should be:
if (CurrentPageID() == “edit” && $Args[“rsnew”][“Approval”] != “0”)

This kinda works but not quite there yet.

Here is the issue… The emails, with a modified subject and body are not sent when the conditions are matched (which is what I wanted) but another default email is sent from the scripts that indicate there was a record edited.

Here is the email that gets sent when the conditions are not matched:

Record status changed as follows:
Table: ChangMGMT
Key value: 41
Action: Updated

When you enable either for “On Add”, “On Edit”, and/or “On Delete” below “Email Notification” from Table setup, then by default system will always send email.

So, you need to add “else” condition in “Email_Sending” server event to customize the Subject and/or the Content of email that suits your needs, too.

I was able to fix it by adding “} elseif { return FALSE; }” at the end of my 3 email scripts. Thanks!

Great. Thanks for the info. That would be very helpful.