【发布时间】:2019-11-18 18:08:13
【问题描述】:
我正在使用 Mailtrap 进行测试。我有这个包含电子邮件地址(收件人)和唯一数据的数组。
array:3 [
0 => array:3 [
"email" => "test1@email.com"
"report" => "Report 1"
"count" => "20"
]
1 => array:3 [
"email" => "test2@email.com"
"report" => "Report 3"
"count" => "10"
]
2 => array:3 [
"email" => "test3@email.com"
"report" => "Report 4"
"count" => "0"
]
]
这是我到目前为止所得到的。该数组存储在$items 变量中。
foreach ($items as $item) {
Mail::send('emails.test', [ 'item' => $item ], function ($m) use($item) {
$m->bcc('test0@mail.com');
$m->to($item['email'])->subject($item['report']);
});
}
它发送前 2 份报告,但我收到“每秒电子邮件太多”的错误。我怎样才能避免这些错误?还是有更好的方法?
【问题讨论】:
-
这个问题已经有了答案[参考这个链接](stackoverflow.com/questions/35304197/…)
-
错误是php异常吗?您可以添加一个带有小超时的 try catch,然后重试发送。
-
正如邮件陷阱定价页面所说:使用免费计划,您每 10 秒只能发送 2 封邮件。每收到两封邮件,您必须等待 10 秒。
-
只需在循环中添加
sleep(5)? -
@Don'tPanic 我想我唯一的选择是添加延迟。
标签: php laravel-5 laravel-mail