laravel5.5 Auth 发送邮箱重置密码

laravel5.5 Auth 认证 发送邮箱重置密码

1、快速入门(#f4645f

Laravel 通过运行如下命令可快速生成认证所需要的路由和视图:

php artisan make:auth

2、把resource/views/  auth下和 layouts下的视图文件的英文改成中文

3、配置语言包

composer require "overtrue/laravel-lang:~3.0"

config/app.php

Illuminate\Translation\TranslationServiceProvider::class,

替换:

Overtrue\LaravelLang\TranslationServiceProvider::class,

Lumen

bootstrap/app.php

$app->register(Overtrue\LaravelLang\TranslationServiceProvider::class);

Laravel

config/app.php:

'locale' => 'zh-CN',

Lumen

.env:

APP_LOCALE=zh-CN

发布语言包到你的项目目录 resources/lang/ 中:

$ php artisan lang:publish zh-CN

4、开通邮箱授权码,这里已163举例:

.env 配置:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.163.com
MAIL_PORT=25
MAIL_USERNAME=123456@163.com
MAIL_PASSWORD=123456//这里写163给你的授权码
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=123456@163.com//这里要和username一致
MAIL_FROM_NAME=laravel//你可以自定义

email 模板设置:

 Laravel 默认的 Notification ClassResetPassword,位于 Illumintate/Auth/Notifications:

<?php

namespace Illuminate\Auth\Notifications;

use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;

class ResetPassword extends Notification
{
    /**
     * The password reset token.
     *
     * @var string
     */
    public $token;

    /**
     * Create a notification instance.
     *
     * @param  string  $token
     * @return void
     */
    public function __construct($token)
    {
        $this->token = $token;
    }

    /**
     * Get the notification's channels.
     *
     * @param  mixed  $notifiable
     * @return array|string
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Build the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->line('您收到这封电子邮件,因为我们收到了您的帐号密码重置请求。')
            ->line('You are receiving this email because we received a password reset request for your account.')
            ->action('重置密码', url(config('app.url').route('password.reset', $this->token, false)))
            ->line('如果您不要求重置密码,则不需要进一步的操作。')
            ->line('If you did not request a password reset, no further action is required.');
    }
}

 

php artisan vendor:publish --tag=laravel-notifications

以上命令把包裹里的模板发布到resources/views/vendor/notifications文件夹中,这样我们只需要修改resources/views/vendor/notifications/email.blade.php就可以了。

@component('mail::message')
{{-- Greeting --}}
@if (! empty($greeting))
# {{ $greeting }}
@else
@if ($level == 'error')
# Whoops!
@else
# Hello!
@endif
@endif

{{-- Intro Lines --}}
@foreach ($introLines as $line)
{{ $line }}

@endforeach

{{-- Action Button --}}
@isset($actionText)
<?php
    switch ($level) {
        case 'success':
            $color = 'green';
            break;
        case 'error':
            $color = 'red';
            break;
        default:
            $color = 'blue';
    }
?>
@component('mail::button', ['url' => $actionUrl, 'color' => $color])
{{ $actionText }}
@endcomponent
@endisset

{{-- Outro Lines --}}
@foreach ($outroLines as $line)
{{ $line }}

@endforeach

{{-- Salutation --}}
@if (! empty($salutation))
{{ $salutation }}
@else
Regards,<br>{{ config('app.name') }}
@endif

{{-- Subcopy --}}
@isset($actionText)
@component('mail::subcopy')
如果你在点击 "{{ $actionText }}" 按钮时遇到麻烦,复制并粘贴下面的网址到你的网页浏览器:<br>
If you’re having trouble clicking the "{{ $actionText }}" button, copy and paste the URL below
into your web browser: [{{ $actionUrl }}]({{ $actionUrl }})
@endcomponent
@endisset
@endcomponent

测试邮件即可!

posted @ 2017-09-26 15:30  丶老中医  阅读(554)  评论(0编辑  收藏  举报
一切已经开始©2018 丶老中医