cc
记录在Laravel DocsIlluminate\Mail\Mailer
中,但我在源代码中找不到方法或属性,在Laravel API 文档中也找不到。所以你不能这样使用它。
但Illuminate\Mail\Mailable
有财产cc
。所以,如果你想cc
在发送前添加并to
在构建方法上添加,你需要这样的东西:
MyMailAlert.php
class MyMailAlert extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*/
public function __construct()
{
//
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject($this->subject)->to($this->to)->view('my-mail');
}
}
在您的控制器中:
$myMailAlert = new MyMailAlert();
$myMailAlert->cc = $cc_mail;
// At this point you have cc already setted.
Mail::send($myMailAlert); // Here you sends the mail
注意 build 方法使用mailable 实例subject
的to
属性,所以你必须在发送之前设置它。
我不确定您从哪里检索您的$subject
and$to_email
在您的构建方法示例中,但对于我的示例,您必须将这些值提供给$myMailAlert->subject
and $myMailAlert->to
。您可以在构建方法中使用自定义变量,但鉴于该类已经具有这些属性,因此不需要自定义变量。