我正在尝试更改Laravel5.7附带的验证电子邮件中的默认subject字段。我该怎么改,在哪里改?我已经搜遍了所有的地方和网上。因为这是全新的我找不到答案。
发布于 2018-09-19 22:40:34
你不需要编码任何东西。通知将所有字符串包装在Lang类中,以便您可以提供从英语到另一种语言的翻译字符串,如果您只想更改措辞,甚至可以将英语翻译成英语。
看看/vendor/laravel/framework/src/Illuminate/Auth/Notifications/VerifyEmail.php
public function toMail($notifiable)
{
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable);
}
return (new MailMessage)
->subject(Lang::getFromJson('Verify Email Address'))
->line(Lang::getFromJson('Please click the button below to verify your email address.'))
->action(
Lang::getFromJson('Verify Email Address'),
$this->verificationUrl($notifiable)
)
->line(Lang::getFromJson('If you did not create an account, no further action is required.'));
}你可以看到所有的字符串。
如果资源/lang文件夹中没有en.json文件,则创建一个文件。
添加原始字符串和替换。例如
{
"Verify Email Address": "My preferred subject",
"Please click the button below to verify your email address.":"Another translation"
}若要转换为另一种语言,请更改config/app.php中的区域设置,并使用locale.json创建一个翻译文件
发布于 2018-09-19 14:33:49
这就是MustVerifyEmail的特点
<?php
namespace Illuminate\Auth;
trait MustVerifyEmail
{
/**
* Determine if the user has verified their email address.
*
* @return bool
*/
public function hasVerifiedEmail()
{
return ! is_null($this->email_verified_at);
}
/**
* Mark the given user's email as verified.
*
* @return bool
*/
public function markEmailAsVerified()
{
return $this->forceFill([
'email_verified_at' => $this->freshTimestamp(),
])->save();
}
/**
* Send the email verification notification.
*
* @return void
*/
public function sendEmailVerificationNotification()
{
$this->notify(new Notifications\VerifyEmail);
}
}正如您所看到的,发送一个名为VerifyEmail的通知,所以我认为用您自己的通知在用户模型上重写这个方法就足够了。您还应该检查这个文件:vendor/laravel/framework/src/Illuminate/Auth/Notifications/VerifyEmail.php,因为它包含通知,可以用作自定义验证通知的示例。
在User.php中
public function sendEmailVerificationNotification()
{
$this->notify(new MyNotification);
}那就跑
php artisan make:notification MyNotification在您的通知中,您只需扩展到Illuminate\Auth\Notifications\VerifyEmail
然后您可以重写通知toMail函数..。还没试过,但那应该管用。
发布于 2018-09-19 14:49:17
你能把你的功能发到你寄的地方吗?我用:
\Mail::to($user)->subject('Your Subject')->bcc([$reports,$me])->send(new Declined($user));这是:发送邮件到$user,设置主题,盲目复制,然后发送邮件,同时传递给用户。这也是特价邮件。您可以使用->操作符来添加邮件的所有附加内容,这样您就可以添加密件抄送(就像我所做的那样)和CC等。
https://stackoverflow.com/questions/52408042
复制相似问题