【问题标题】:How can I send email to multiple recipients with their own unique contents?如何将电子邮件发送给具有自己独特内容的多个收件人?
【发布时间】: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


【解决方案1】:

正如 Mailtrap 所说,免费计划仅允许每 10 秒接收 10 封电子邮件。

https://mailtrap.io/pricing

您需要等待 10 秒,然后再发送下一个 2。

【讨论】:

    猜你喜欢
    • 2018-11-19
    • 2013-09-02
    • 2019-06-17
    • 1970-01-01
    • 2015-11-30
    • 2016-08-11
    • 2016-08-21
    • 1970-01-01
    • 2019-03-01
    相关资源
    最近更新 更多