【问题标题】:Laravel: Get bad_domains from MailableLaravel:从 Mailable 中获取 bad_domains
【发布时间】:2018-09-14 18:11:46
【问题描述】:

我正在使用 Laravel 发送邮件,如下所示:

foreach ($users as $user) {
   \Mail::to($user())->send(new Newsletter($user));
}

我想要一个包含所有有 bad_domain 响应的用户的数组。我在docs 中发现 Laravel 使用 Swiftmailer,它有a way to find bad_domain respones

// Pass a variable name to the send() method
if (!$mailer->send($message, $failures))
{
  echo "Failures:";
  print_r($failures);
}

/*
Failures:
Array (
  0 => receiver@bad-domain.org,
  1 => other-receiver@bad-domain.org
)
*/

但是,我想使用 Mailable 类。我不确定如何使用 Swiftmailer(我可以通过 \Mail::getSwiftMailer() 访问)来做到这一点。

在使用 Laravel 的 Mailable 时,有什么简单的方法可以获取 bad_domains 吗?

【问题讨论】:

    标签: php laravel swiftmailer


    【解决方案1】:

    您只能访问 bad_domains,但不能使用 Swiftmailer (Swiftmailer 4 does not retrieve bounces as $failedRecipients) 退回。

    可以通过

    获得bad_domains
    \Mail::to($user)->send(new \App\Mail\Hi());
    
    dd(\Mail::failures());
    

    Illuminate\Mail\Mailer.php

      /**
         * Send a Swift Message instance.
         *
         * @param  \Swift_Message  $message
         * @return void
         */
        protected function sendSwiftMessage($message)
        {
            try {
                return $this->swift->send($message, $this->failedRecipients);
            } finally {
                $this->forceReconnection();
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2017-07-01
      • 2018-12-13
      • 2021-06-26
      • 1970-01-01
      • 2018-08-28
      • 2018-07-12
      • 2018-10-19
      • 1970-01-01
      • 2020-02-06
      相关资源
      最近更新 更多