I am having a super strange issue, I will explain in detail why it is strange after the facts...
The code...
Mail::send('emails.cron.loggedinusers', $data, function($message){
// Get Admin user emails
$adminUserEmails = DB::table('users')->where('user_role', 'admin')->lists('email');
// Build nice comma separated list of Admin Emails addresses
// and also wrap each email in quotes
$filter = function($adminUserEmails){ return "'$adminUserEmails'"; };
$toEmails = array_map($filter, $adminUserEmails);
$toEmails = implode(', ', array_values($toEmails));
print_r($toEmails);
// Send email to Admins Only
$message->from('one@email.com', 'Jason');
$message->to('one@email.com')->cc($toEmails);
$message->subject('[TIMECLOCK ALERT] Users are logged into the Timeclock!');
});
When I run this code above which gets 4 Email address from the database and tries to email to them, I get this nasty error message...
Keep in mind I have changed the actual email values shown here to protect there identity but the REAL emails in the script are all legit emails...
Swift_RfcComplianceException
Address in mailbox given ['one@email.com', 'two@email.com',
'three@email.com', 'four@email.com']
does not comply with RFC 2822, 3.6.2.
Now if I replace the variable $toEmails
with the actual string text...
$message->to('one@email.com')->cc('one@email.com', 'two@email.com', 'three@email.com', 'four@email.com');
Then it sends the emails without an issue and no error messages!
This is strange and weird to me because I am literally printing the $toEmails
variable to screen and copy/pasting it's output into the email code above and it mails just fine but as soon as I use the variable instead of the text string, I get that awful error message above. I cannot make any sense of why this would do this, please if you have any ideas please share with me???