首页 > 解决方案 > Laravel 使用 mail::to 发送电子邮件而不查看其他收件人

问题描述

我有一组收件人$this->recipients,我想向所有收件人发送电子邮件而不显示彼此的电子邮件。目前,它显示电子邮件中的所有收件人。 在此处输入图像描述

 if (count($this->recipients) > 1) {
                Mail::bcc($this->recipients)
                    ->send(new EmailNotificationMailable($this->notificationRequest));
            } else {
                Mail::to($this->recipients)
                    ->send(new EmailNotificationMailable($this->notificationRequest));
            }

我试过这段代码,但是当我用Mail::bcc电子邮件发送时To是空的。请为此提供有效的解决方案。我不想循环收件人数组

标签: phplaravel

解决方案


您需要遍历收件人集合:

if(count($this->recipients) > 1)
{
 $this->recipients->each(function($recipient)
 {
    Mail::to(recipient)->bcc($this->recipients)->send(new EmailNotificationMailable($this->notificationRequest));
 }
}else{
    Mail::to($this->recipients)->send(new EmailNotificationMailable($this->notificationRequest));
}

推荐阅读