Hello,
I have a problem on sending email notification to multiple receipt using sendmail() when a recod is updated.
The code below works great for sending email to one receipt:
function Kontratat_after_update($data, $memberInfo, &$args) {
if($data['alert'] != $GLOBALS['old_data']['alert'])
{
sendmail(array(
'to' => '[email protected]',
'name' => 'Contract Alert',
'subject' => 'Alert status changed for Contract ' . $data['id_kontrata'],
'message' =>'old data'. $GLOBALS['old_data']['alert'].'new data'.$data['alert']
));
}
return TRUE;
}
I have tried to to use multiple emails separating with comma like:
'to' => '[email protected], [email protected]', but it doesnt work.
Please any solution?
Regards
Sending email to multiple receipt with sendmail()
Re: Sending email to multiple receipt with sendmail()
In AppGini's sendmail implementation there is a validation of "to" parameter based on a regular expression. If I'm right, this regEx-check returns FALSE for your comma-concatenated email addresses. It should return TRUE for a single (!) email address.
This means for AppGini the given string (multiple email addresses) is NOT a valid (single) email address. Therefore the message will not be sent.
Alternatives as a starting point
Code: Select all
function isEmail($email) {
if(preg_match('/^([*+!.&#$�\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,45})$/i', $email)) {
return $email;
}
return false;
}
Alternatives as a starting point
- iterate through the recipients (foreach) and send the same email to exactly one recipient per iteration
- implement a custom sendmail function based on PHPMailer, which is already included in your sourcecode (./resources/PHPMailer/) by default
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 with sendmail()
Hi,
maybe not exactly what you need, but you could also use the hooks/__global.php -> sendmail_handler
You would need to add possibly some logic if you send from different forms, but basically add
That will send the mail in addition to MAILADDRESS
maybe not exactly what you need, but you could also use the hooks/__global.php -> sendmail_handler
You would need to add possibly some logic if you send from different forms, but basically add
Code: Select all
$pm->addCC('MAILADDRESS', 'NAME');
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.
Re: Sending email to multiple receipt with sendmail()
Thank you both for your reply jsetzer and pböttcher,
I solved it with the code below by adding emails address on array and then sending email notification with foreach statement:
$receipt=array('[email protected]','[email protected]','[email protected]');
if($data['alert'] != $GLOBALS['old_data']['alert']){
foreach ($receipt as $address){
sendmail(array(
'to' => $address,
'name' => 'Contract Alert',
'subject' => 'Alert status changed for Contract ' . $data['id_kontrata'],
'message' =>'old data'. $GLOBALS['old_data']['alert'].'new data'.$data['alert']
));
}
}
I solved it with the code below by adding emails address on array and then sending email notification with foreach statement:
$receipt=array('[email protected]','[email protected]','[email protected]');
if($data['alert'] != $GLOBALS['old_data']['alert']){
foreach ($receipt as $address){
sendmail(array(
'to' => $address,
'name' => 'Contract Alert',
'subject' => 'Alert status changed for Contract ' . $data['id_kontrata'],
'message' =>'old data'. $GLOBALS['old_data']['alert'].'new data'.$data['alert']
));
}
}
Re: Sending email to multiple receipt with sendmail()
I used the php mailer, comma delimiter worked. I would be fearful that iterating through a large list impacts performance on this page and adds extra work on your outbound email router.
Did you try a semi-colon? Seems like an AG bug if we can't send to a list.
Did you try a semi-colon? Seems like an AG bug if we can't send to a list.
Re: Sending email to multiple receipt with sendmail()
Would anyone be able to help me use this solution? I'm no coder!! Please help, I want to use sendmail also to send to multiple recipients.
Re: Sending email to multiple receipt with sendmail()
I know, this is an old thread but today I had to solve this issue and wanted to find a solution right inside the calling method without using
One idea came into my mind, honestly speaking, there is one backdraw, but maybe this idea can help others. With built in options of AppGini's
Backdraw
Only the first recipient will be addressed as "TO", all the others will be addresses in "CC".
Some code
sendmail_handler
in __global.php
.One idea came into my mind, honestly speaking, there is one backdraw, but maybe this idea can help others. With built in options of AppGini's
sendmail
function I did the following:- Get the list of TO-recipients as an array like
["[email protected]","[email protected]"]
- Take the first array-entry as "TO"-recipient
- Take the rest and pass them as "CC"-recipients-array
Backdraw
Only the first recipient will be addressed as "TO", all the others will be addresses in "CC".
Some code
Code: Select all
// prepare your $subject and $body contents
// get your recipients' email addresses as an array AND REVERSE IT
$recipients = array_reverse(["[email protected]","[email protected]","[email protected]"]);
// nothing to do
if (sizeof($recipients) < 1) return false;
$to = array_pop($recipients);
$cc = array_reverse($recipients);
$mail = [
"to" => $to,
"cc" => $cc,
"subject" => $subject,
"message" => $body
];
$result = sendmail($mail);
if ($result !== true) die($result);
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