【发布时间】:2020-09-08 01:08:38
【问题描述】:
我正在按照教程在enter link description here 上使用护照身份验证构建 API 我已经按照第 1 部分并通过 帐户确认和通知 浏览了第 2 部分,但最终在我在 POSTMAN 上进行测试时遇到了问题。问题是,它只会向数据库添加没有带有错误的邮件。我不知道我需要在 .env 或 mail.php 中进行任何配置。当我尝试配置电子邮件地址、STMP 和密码时。再次显示相同的错误,我在这里看到的大多数问题都完全不同,因为大多数问题都与 mail.php 和 .env 有关,我不知道,因为教程链接上没有这样的问题,我什至尝试更改邮件.php 和 .env,我运行 php artisan cache:clear 但显示相同的错误。
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class SignupActivate extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
$url = url('/api/auth/signup/activate/'.$notifiable->activation_token);
return (new MailMessage)
->subject('Confirm your account')
->line('Thanks for signup! Please before you begin, you must confirm your account.')
->action('Confirm Account', url($url))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
我也做过,两种身份验证方式 Mail.php
返回 [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'username@gmail.com'),
'name' => env('MAIL_FROM_NAME', 'Payne Curtis'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
'log_channel' => env('MAIL_LOG_CHANNEL'),
];
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=username@gmail.com
MAIL_PASSWORD=XXXXXXXXXXXXXXX
MAIL_ENCRYPTION=null
【问题讨论】:
-
在
.env中进行任何更改后,运行php artisan cache:clear和 php artisan config:cache` 并重试。 -
是的,我都做到了
-
您是否尝试过 2-verification 并确保您配置了将在 .env 文件中使用的应用密码?
-
是的,我做到了,2 向验证和应用密码