gpt4 book ai didi

laravel-5 - 拉拉维尔 : How to customize title of email when sending email with Mailable?

转载 作者:行者123 更新时间:2023-12-03 06:49:14 25 4
gpt4 key购买 nike

我编写了一个mailable来在用户注册时发送电子邮件,我按照文档(https://laravel.com/docs/5.5/mail)进行操作:

首先,生成可邮寄的邮件:

php artisan make:mail UserRegistered

好的,这样在 app/Mail 目录中有一个 UserRegistered.php 文件,我编写了 build() 方法,如下所示这个:

public function build()
{
return $this->view('emails.activate-user')
->with([
'name' => $this->user->name,
'url' => route('activateUser',['token'=>$this->user->confirmation_token])
]);
}

邮件可以发送成功,邮件的标题是用户已注册,我想自定义标题,怎么做?

最佳答案

您必须使用subject方法

public function build()
{
return $this->view('emails.activate-user')
->subject("My mail title")
->with([
'name' => $this->user->name,
'url' => route('activateUser',['token'=>$this->user->confirmation_token])
]);
}

或者更新邮件类的构造函数

public function __construct()
{

$this->subject('Sample title');
}

关于laravel-5 - 拉拉维尔 : How to customize title of email when sending email with Mailable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46245276/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com