Page 1 of 1

Send mail to a only person

Posted: Tue Apr 18, 2017 11:28 am
by eayvl

Hi, I'm making some changes to the DEMO base in local server (localhost) I need the following please:

  • At the Base Employees says: robert reports to Buchanan Steven, i need that, when robert makes a change in base "Product" Buchanan Steven has that to receive a mail.
  • At the Base Employees says: nancy reports to Fuller Andrew, i need that, when nancy makes a change in base "Product" Fuller Andrew has that to receive a mail.

What part of the code I need to modify?

Thanks.


Re: Send mail to a only person

Posted: Tue Apr 18, 2017 12:21 pm
by mobhar
  1. Define your email settings from "PHP" -> "Email Settings" tab,
  2. Enable "On Edit" under "Table" setup -> "Table-Options" -> "Email Notification" that belongs to "orders" table,
  3. Write your PHP code in "Email_Sending" server event that belongs to "orders" table, in order to customize the Email content/recipient/sender, etc (read "Server Events and Client Scripts" topic from PHPMaker Help menu for more info),
  4. Regenerate ALL the script files again.

Re: Send mail to a only person

Posted: Wed Apr 19, 2017 6:40 am
by eayvl

I already have part of what I need, but it is possible to obtain the previous values ​​and the new values ​​when receiving the mail.

// Email Sending event
function Email_Sending(&$Email, &$Args) {
//var_dump($Email);
//var_dump($Args);
//exit();
if (CurrentPageID() == "edit") { // If edit Page
$Email->Recipient = ew_ExecuteScalar("SELECT Email FROM EMPLOYEES WHERE ReportsTo = '" . $Args["rsnew"]["EmployeeID"] ."'");
$Email->Cc = $Args["rsnew"]["Email"];
$Email->Bcc = "xxxxx@email.com";
$Email->Subject = "My New Subject";
$Email->Content .= "\nAdded by " . CurrentUserName();
$Email->Format = "HTML";
}
return TRUE;
}


Re: Send mail to a only person

Posted: Wed Apr 19, 2017 10:13 am
by mobhar

If you use for Edit Page, then you should get the Employee ID from $Args["rsold"]["EmployeeID"] instead of $Args["rsnew"]["EmployeeID"].


Re: Send mail to a only person

Posted: Wed Apr 19, 2017 1:15 pm
by arbei

Since you need to send an email to the parent user of the current user, then you need to get the email address of the parent user by their ID.

For example:
$Email->Recipient = ew_ExecuteScalar("SELECT Email FROM EMPLOYEES WHERE EmployeeID = " . CurrentUserInfo("ReportTo") ."");


Re: Send mail to a only person

Posted: Wed Apr 19, 2017 11:14 pm
by eayvl

The solution may be in the Database tabla AUDIT Trail get old and new data, when send the mail.

Is there a catalog where i can check, query ALL tags that exist; for example "CurrentUserName(), CurrentUserInfo(), CurrentDateTime() etc.


Re: Send mail to a only person

Posted: Thu Apr 20, 2017 11:29 am
by mobhar

eayvl wrote:
Is there a catalog where i can check, query ALL tags that exist; for example "CurrentUserName(),
CurrentUserInfo(), CurrentDateTime() etc.

There are some useful global functions that generated in "phpfn*.php" file for your references.