After Insert Hook - Send Email Using Field Value NOT ID
Posted: 2018-07-31 18:02
I am using the after_insert hook to send a notification email to organization members when there is a new first aid record created. The cde I'm using is what I copied from the tutorial on this hook (below). The issue I'm having is that the email sends the ID numeric value which is useless to the reader. I want to instead use the actual project name (we're a construction company) that the ID number refers to in the project table. I am not a coder so if you can help, please give me clear instruction of where I need to make changes if it can even be done. Thank you in advance!
///// Here is the code I'm currently using /////
function firstaid_after_insert($data, $memberInfo, &$args){
/ to compose a message containing the submitted data,
// we need to iterate through the $data array
foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}
@mail(
// mail recipient
"[email protected]",
// subject
"A FIRST AID report has been submitted",
// message
"The following FIRST AID REPORT was submitted by {$memberInfo['username']} This is raw data from the report, share it with crews.: \n\n".
$messageData,
// sender address
"From: [email protected]"
);
//end email code
return TRUE;
}
///// Here is the code I'm currently using /////
function firstaid_after_insert($data, $memberInfo, &$args){
/ to compose a message containing the submitted data,
// we need to iterate through the $data array
foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}
@mail(
// mail recipient
"[email protected]",
// subject
"A FIRST AID report has been submitted",
// message
"The following FIRST AID REPORT was submitted by {$memberInfo['username']} This is raw data from the report, share it with crews.: \n\n".
$messageData,
// sender address
"From: [email protected]"
);
//end email code
return TRUE;
}