Page 1 of 1

Send some fields in the mail

Posted: 2022-01-19 15:56
by espo
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.

Re: Send some fields in the mail

Posted: 2022-01-19 18:03
by pbottcher
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.

Re: Send some fields in the mail

Posted: 2022-01-20 14:27
by espo
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!