I can\'t seem to successfully send to multiple addresses when using Laravel\'s Mail::send()
callback, the code does however work when I only sp
I am using Laravel 5.6 and the Notifications Facade.
If I set a variable with comma separating the e-mails and try to send it, I get the error: "Address in mail given does not comply with RFC 2822, 3.6.2"
So, to solve the problem, I got the solution idea from @Toskan, coding the following.
// Get data from Database
$contacts = Contacts::select('email')
->get();
// Create an array element
$contactList = [];
$i=0;
// Fill the array element
foreach($contacts as $contact){
$contactList[$i] = $contact->email;
$i++;
}
.
.
.
\Mail::send('emails.template', ['templateTitle'=>$templateTitle, 'templateMessage'=>$templateMessage, 'templateSalutation'=>$templateSalutation, 'templateCopyright'=>$templateCopyright], function($message) use($emailReply, $nameReply, $contactList) {
$message->from('myemail@somecompany.com', 'Some Company Name')
->replyTo($emailReply, $nameReply)
->bcc($contactList, 'Contact List')
->subject("Subject title");
});
It worked for me to send to one or many recipients.