[英]Laravel Email Verification Template Location
I have been reading from the documentation about the new feature of laravel the email verification.我一直在阅读有关 laravel 电子邮件验证新功能的文档。 Where can I locate the email template that is sent to the user?
在哪里可以找到发送给用户的电子邮件模板? It does not show here: https://laravel.com/docs/5.7/verification#after-verifying-emails
它没有在这里显示: https : //laravel.com/docs/5.7/verification#after-verifying-emails
Laravel uses this method of VerifyEmail notification class for send email: 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.'));
}
Method in source code . 源代码中的方法。
If you wanna use your own Email template, you can extend Base Notification Class.如果您想使用自己的电子邮件模板,您可以扩展基本通知类。
app/Notifications/
file VerifyEmail.php
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;
and和
/**
* Send the email verification notification.
*
* @return void
*/
public function sendEmailVerificationNotification()
{
$this->notify(new VerifyEmail); // my notification
}
Also if you need blade template:另外,如果您需要刀片模板:
laravel will generate all of the necessary email verification views when the
make:auth
command is executed.执行
make:auth
命令时,laravel 将生成所有必要的电子邮件验证视图。 This view is placed inresources/views/auth/verify.blade.php
.该视图位于
resources/views/auth/verify.blade.php
。 You are free to customize this view as needed for your application.您可以根据应用程序的需要自由自定义此视图。
Answer in comment already.已经在评论中回答了。 Sent by the
toMail()
method.由
toMail()
方法发送。
vendor\laravel\framework\src\Illuminate\Auth\Notifications\VerifyEmail::toMail();
For template structure and appearance;用于模板结构和外观; take a look at this locations also and you can also publish to modify the template:
也看看这个位置,你也可以发布来修改模板:
\vendor\laravel\framework\src\Illuminate\Notifications\resources\views\email.blade.php
\vendor\laravel\framework\src\Illuminate\Mail\resources\views\
To publish those locations:要发布这些位置:
php artisan vendor:publish --tag=laravel-notifications
php artisan vendor:publish --tag=laravel-mail
After running this command, the mail notification templates will be located in the resources/views/vendor
directory.运行此命令后,邮件通知模板将位于
resources/views/vendor
目录中。
Colors and style are controlled by the CSS file in resources/views/vendor/mail/html/themes/default.css
颜色和样式由
resources/views/vendor/mail/html/themes/default.css
的 CSS 文件控制
Also, if you want to translate standard mail VerifyEmail (or other where use Lang::fromJson(...)), you need create new json file in resources/lang/ and name it ru.json, for example.此外,如果您想翻译标准邮件VerifyEmail (或其他使用 Lang::fromJson(...) 的地方),您需要在 resources/lang/ 中创建新的 json 文件并将其命名为 ru.json,例如。 It may contain (resources/lang/ru.json) text below and must be valid.
它可能包含下面的 (resources/lang/ru.json) 文本并且必须是有效的。
{
"Verify Email Address" : "Подтверждение email адреса"
}
Actually they do not use any blade or template files.实际上他们不使用任何刀片或模板文件。 They create notifications and write code for it in notifications.
他们创建通知并在通知中为其编写代码。
Look I do that very easy do the following steps :
看我这样做很容易,请执行以下步骤:
In Route File在路由文件中
Auth::routes(['verify' => true]);
In AppServiceProvider.php File
在 AppServiceProvider.php 文件中
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);
});
}
}
Now Create EmailVerification With Markdown
现在使用 Markdown 创建电子邮件验证
php artisan make:mail EmailVerification --markdown=emails.verify-email
Edit The EmailVerrification as you want and the blade file根据需要编辑 EmailVerrification 和刀片文件
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]);
}
}
in the blade file change the design as you want and use verifyUrl to display the verification link and $user to display user information
在刀片文件中根据需要更改设计并使用 verifyUrl 显示验证链接和 $user 显示用户信息
thanks, happy coding :)谢谢,快乐编码:)
vendor\laravel\framework\src\Illuminate\Mail\resources\views\html
您将在此文件位置找到 Laravel 默认电子邮件模板。
If a notification supports being sent as an email, you should define a toMail method on the notification class.如果通知支持作为电子邮件发送,您应该在通知类上定义一个 toMail 方法。 This method will receive a $notifiable entity and should return a Illuminate\\Notifications\\Messages\\MailMessage instance.
此方法将接收一个 $notifiable 实体,并应返回一个 Illuminate\\Notifications\\Messages\\MailMessage 实例。 Mail messages may contain lines of text as well as a "call to action".
邮件消息可能包含文本行以及“号召性用语”。
/**
* 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!');
}
You can use the laravel e-mail builder as documented here: https://laravel.com/docs/5.8/notifications#mail-notifications .您可以使用此处记录的 laravel 电子邮件生成器: https ://laravel.com/docs/5.8/notifications#mail-notifications。 Laravel will take care of the e-mail view.
Laravel 会处理电子邮件视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.