Toffer
Toffer

Reputation: 79

How can I send email to multiple recipients with their own unique contents?

I am using Mailtrap for testing. I have this array that contains the email address (recipient) and unique data.

array:3 [
  0 => array:3 [
    "email" => "[email protected]"
    "report" => "Report 1"
    "count" => "20"
  ]
  1 => array:3 [
    "email" => "[email protected]"
    "report" => "Report 3"
    "count" => "10"
  ]
  2 => array:3 [
    "email" => "[email protected]"
    "report" => "Report 4"
    "count" => "0"
  ]
]

Here's what I got so far. The array is stored in $items variable.

foreach ($items as $item) {

            Mail::send('emails.test', [ 'item' => $item ], function ($m) use($item) {

                $m->bcc('[email protected]');
                $m->to($item['email'])->subject($item['report']);

            });

        }

It sends the first 2 reports, but I get an error "too many emails per second". How can I avoid these error? or Is there a better approach?

Upvotes: 0

Views: 593

Answers (1)

Patrick Schocke
Patrick Schocke

Reputation: 1491

As Mailtrap says, the free plan only allowes 10 emails to be received every 10 seconds.

https://mailtrap.io/pricing

You need to wait 10 sec before you send the next 2.

Upvotes: 1

Related Questions