简体   繁体   中英

Sending Emails to Many Recipients in The 1000's Using Laravel and Mailgun

I am using Laravel 5.5 and Mailgun. I want to send email campaigns to over 700 recipients and likely this list will grow into the thousands. Currently I am looping through each email address and sending the emails one at a time. As a result usually only about 530 emails go out. I have searched the net and cannot seem to find a good explanation on how to approach this in a more efficient way so that all the emails are sent. Any suggestions would be greatly appreciated.

public function mailCampaign()
{

    //Code to get all email data in JSON

    $emails= json_decode($data->getBody());
    $baseUrl = config('constants.base_url');

    foreach($emails as $key => $email){
        Mail::to($email)
            ->send(new EmailInstance($variable, $email, $baseUrl));
    }
    $data = ['message' => 'Success. Emails have been sent.'];
    return response()->view('emails.mail', $data, 200);
}

You shouldn't send emails one by one. Use Mailgun API instead. You can send thousands of emails using API with Bogardo/Mailgun package.

Mailgun supports the ability send to a group of recipients through a single API call. This is achieved by specifying multiple recipient email addresses as to parameters and using Recipient Variables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM