我一直在阅读有关Laravel新功能“电子邮件验证”的文档。我应该在哪里找到发送给用户的电子邮件模板?它在这里没有显示:https://laravel.com/docs/5.7/verification#after-verifying-emails
我一直在阅读有关Laravel新功能“电子邮件验证”的文档。我应该在哪里找到发送给用户的电子邮件模板?它在这里没有显示:https://laravel.com/docs/5.7/verification#after-verifying-emails
Laravel使用VerifyEmail通知类的此发送电子邮件的方法:
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.'));
}
如果您想使用自己的电子邮件模板,可以扩展基本通知类。
app/Notifications/
文件夹下创建VerifyEmail.php
文件<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Lang;
use Illuminate\Auth\Notifications\VerifyEmail as VerifyEmailBase;
class VerifyEmail extends VerifyEmailBase
{
// use Queueable;
// change as you want
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.'));
}
}
use App\Notifications\VerifyEmail;
和
/**
* Send the email verification notification.
*
* @return void
*/
public function sendEmailVerificationNotification()
{
$this->notify(new VerifyEmail); // my notification
}
如果您需要Blade模板:
当执行
make:auth
命令时,Laravel将生成所有必要的电子邮件验证视图。此视图放置在resources/views/auth/verify.blade.php
中。您可以自由地根据应用程序的需要对此视图进行自定义。
来源。
已在评论中回答。由toMail()
方法发送。
vendor\laravel\framework\src\Illuminate\Auth\Notifications\VerifyEmail::toMail();
关于模板结构和外观,请查看这些位置,您也可以发布以修改模板:
\vendor\laravel\framework\src\Illuminate\Notifications\resources\views\email.blade.php
\vendor\laravel\framework\src\Illuminate\Mail\resources\views\
发布这些位置:php artisan vendor:publish --tag=laravel-notifications
php artisan vendor:publish --tag=laravel-mail
运行此命令后,电子邮件通知模板将位于resources/views/vendor
目录中。颜色和样式由resources/views/vendor/mail/html/themes/default.css
中的CSS文件控制。email.blade.php
是一个组件,哪个模板使用了这个组件,我该如何自定义它呢?谢谢。 - Zahra19977{
"Verify Email Address" : "Подтверждение email адреса"
}
实际上他们不使用任何刀片或模板文件。他们在通知中创建通知并编写相应的代码。
看,我很容易做到这一点 按照以下步骤操作:
在路由文件中
Auth::routes(['verify' => true]);
namespace App\Providers;
use App\Mail\EmailVerification;
use Illuminate\Support\ServiceProvider;
use View;
use URL;
use Carbon\Carbon;
use Config;
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Notifications\Messages\MailMessage;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// Override the email notification for verifying email
VerifyEmail::toMailUsing(function ($notifiable){
$verifyUrl = URL::temporarySignedRoute('verification.verify',
\Illuminate\Support\Carbon::now()->addMinutes(\Illuminate\Support\Facades
\Config::get('auth.verification.expire', 60)),
[
'id' => $notifiable->getKey(),
'hash' => sha1($notifiable->getEmailForVerification()),
]
);
return new EmailVerification($verifyUrl, $notifiable);
});
}
}
php artisan make:mail EmailVerification --markdown=emails.verify-email
按照您的需求编辑电子邮件验证和刀片文件
class EmailVerification extends Mailable
{
use Queueable, SerializesModels;
public $verifyUrl;
protected $user;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($url,$user)
{
$this->verifyUrl = $url;
$this->user = $user;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$address = 'mymail@gmail.com';
$name = 'Name';
$subject = 'verify Email';
return $this->to($this->user)->subject($subject)->from($address, $name)->
markdown('emails.verify',['url' => $this->verifyUrl,'user' => $this->user]);
}
}
vendor\laravel\framework\src\Illuminate\Mail\resources\views\html
你可以在这个文件位置找到Laravel默认的电子邮件模板。
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
$url = url('/invoice/'.$this->invoice->id);
return (new MailMessage)
->greeting('Hello!')
->line('One of your invoices has been paid!')
->action('View Invoice', $url)
->line('Thank you for using our application!');
}
您可以按照此处的文档https://laravel.com/docs/5.8/notifications#mail-notifications使用Laravel电子邮件构建器。 Laravel将负责电子邮件视图。
vendor\laravel\framework\src\Illuminate\Auth\Notifications\VerifyEmail::toMail()
方法发送的。 - laze