I am using Mailgun to handle email in my Laravel 5.1 application. There are times when I need to email a large number of users at once, such as internal group emails and alert notices. So far, I have created an array of recipient email addresses, sent the email to a webmaster type address, and included the end recipients in BCC:
$recipients = [];
foreach (User::emailRecipients()->get() as $user)
{
$recipients[] = $user->email;
}
$data['message'] = "Hello World";
$data['recipients'] = $recipients;
Mail::send('emails.group-email', $data, function($message) use ($data) {
$message->to('support@demo.com')
->bcc($data['recipients'])
->subject('Test message');
});
While this works, it's not ideal. For starters, I cannot reference anything unique to each recipient within the email (such as a custom unsubscribe link). I cannot use some sort of mailing list on an email provider because the recipients will never be the same, it all depends on several factors.
The next logical step is to iterate over each email address and use Mail::send
on each iteration. But would this cause any performance issues or API restrictions with Mailgun? It's possible that one email could be sent to approximately 200 recipients.