V1nznt
December 24, 2015, 9:47am
1
Is it possible to send an email to multiple recipients using Kirby’s email() function?
I’ve tried the following:
$email = email(array(
'to' => 'info@company.com,administration@company.com',
'from' => $data['email'],
'subject' => 'Contactform',
'body' => $body
));
Unfortunately that doesn’t work. I get the error message “Invalid recipient” because it tries to validate the input. Any ideas if this is possible? Right now i’m just calling the function twice, but that doesn’t really feel right.
Try (not tested!):
Use
'to' => 'info@company.com;administration@company.com',
instead of
(change “,” to “;” like most email programs do).
Good luck!
V1nznt
December 24, 2015, 10:01am
3
Nope, doesn’t work either. Still got the ‘Invalid recipient’ error…
That does not currently work unfortunately. I think Kirby should accept an array with multiple addresses there, but that’s not already supported.
I have opened an issue on GitHub .
1 Like
V1nznt
December 24, 2015, 11:18am
5
Yeah I also tried setting an array with multiple addresses. Thanks for opening an issue!
For the moment:
$email = array(
'to' => array( 'info@company.com','administration@company.com'),
'from' => $data['email'],
'subject' => 'Contactform',
'body' => $body
),
foreach($email['to'] as $to) {
$result = email(a::merge($email, array('to' => $to));
}
Actually it’s far more simple:
$email = email(array(
'from' => $data['email'],
'subject' => 'Contactform',
'body' => $body
));
foreach(array('info@company.com','administration@company.com') as $to) {
$result = $email->send(array('to' => $to));
}
But I will implement the array option as well.
1 Like