Send some fields in the mail

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Send some fields in the mail

Post by espo » 2022-01-19 15:56

Hi everyone.
I used this code to send an email after updating the page.

Code: Select all

function tablename_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";
    }
 
    sendmail(array(
        'to' => '[email protected]',
        'name' => 'Recipient Name',
         
        'subject' => 'A new record needs your attention',
         
        'message' => "The following new record was submitted by {$memberInfo['username']}: \n\n" . $messageData
    ));
     
    return true;
}
The email sends all the fields of the DB.
Would it be possible to send only some fields?
Could you explain to me how to do it?

Thanks so much.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Send some fields in the mail

Post by pbottcher » 2022-01-19 18:03

Hi,

you can try something like:

Code: Select all

    foreach($data as $field => $value){
        $messagefields=['YOURFIELD1','YOURFIELD2', .....];
        if (in_array($field,$messagefields)) {
           $messageData .= "$field: $value \n";
       }    
   }
Put all fields that you want to send in the array $messagefields.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Re: Send some fields in the mail

Post by espo » 2022-01-20 14:27

Thanks so much,

I do some tests and let you know.

Another question, but can I enter multiple recipients?
I tried to enter two email addresses but it doesn't work.

Code: Select all

sendmail(array(
        'to' => '[email protected]', '[email protected]',
        'name' => 'Recipient Name',
         
        'subject' => 'A new record needs your attention',
         
        'message' => "The following new record was submitted by {$memberInfo['username']}: \n\n" . $messageData
    ));
How can I solve?
Thanks!

Post Reply