Good morning,
I wanted to send an email to multiple recipients via hook, but it doesn't work.
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], [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;
}
Can you help me understand how to solve?
Many thanks in advance.
Sending email to multiple receipt
Re: Sending email to multiple receipt
Maybe this older thread can help:
viewtopic.php?f=7&t=3799&p=14327&hilit=email+cc#p14298
viewtopic.php?f=7&t=3799&p=14327&hilit=email+cc#p14298
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: Sending email to multiple receipt
Thanks a lot jsetzer.
I had already seen the post but not being so experienced I did some tests without success.
Could you help me understand with an example how to send an email to multiple recipients?
Thanks a lot.
I had already seen the post but not being so experienced I did some tests without success.
Could you help me understand with an example how to send an email to multiple recipients?
Thanks a lot.
Re: Sending email to multiple receipt
Hello,
I did some tests and with the following change, send to more recipients.
But I have a problem.
Send 17 emails. One for each string in the table.
Where am I wrong?
function myone_sped_after_update($data, $memberInfo, &$args) {
// to compose a message containing the submitted data,
// we need to iterate through the $data array
$receipt=array('[email protected]','[email protected]');
foreach($data as $field => $value){
$messageData .= "$field: $value \n";
foreach ($receipt as $address){
sendmail(array(
'to' => $address,
'name' => 'Recipient Name',
'subject' => 'Spedizione Modificata',
'message' => "{$memberInfo['username']} ha modificato una spedizione \n\n" . $messageData
));
}
}
return TRUE;
}
I did some tests and with the following change, send to more recipients.
But I have a problem.
Send 17 emails. One for each string in the table.
Where am I wrong?
function myone_sped_after_update($data, $memberInfo, &$args) {
// to compose a message containing the submitted data,
// we need to iterate through the $data array
$receipt=array('[email protected]','[email protected]');
foreach($data as $field => $value){
$messageData .= "$field: $value \n";
foreach ($receipt as $address){
sendmail(array(
'to' => $address,
'name' => 'Recipient Name',
'subject' => 'Spedizione Modificata',
'message' => "{$memberInfo['username']} ha modificato una spedizione \n\n" . $messageData
));
}
}
return TRUE;
}
Re: Sending email to multiple receipt
I think you have mixed up the two foreach-loops.
Create your message first. Then use foreach to send it to each recipient:
not tested code:
PS: Please, when posting code, format it using code-tool [</>] in "Full Editor" mode for better readability
(app.php/help/bbcode#f2r1).
Create your message first. Then use foreach to send it to each recipient:
not tested code:
Code: Select all
function myone_sped_after_update($data, $memberInfo, &$args) {
$receipt=array('[email protected]','[email protected]');
// compose message
foreach($data as $field => $value)
{
$messageData .= "$field: $value \n";
} // I have moved this bracket from the bottom up here
// send to each recipient
foreach ($receipt as $address)
{
sendmail(array(
'to' => $address,
'name' => 'Recipient Name',
'subject' => 'Spedizione Modificata',
'message' => "{$memberInfo['username']} ha modificato una spedizione \n\n" . $messageData
));
}
return TRUE;
}
(app.php/help/bbcode#f2r1).
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: Sending email to multiple receipt
I solved, thanks a lot for the support.