我正在尝试在用户注册时向他们发送电子邮件验证链接,但我收到一条消息Authentication required,但没有发送邮件。我尝试将 mailtrap 用于演示和 sendgrid,我将在生产中使用它们,但消息是相同的。这就是我要做的运行后,composer require guzzlehttp/guzzle我像这样更新了我的 env 文件# MAIL_DRIVER=smtp# MAIL_HOST=smtp.mailtrap.io# MAIL_PORT=2525# MAIL_USERNAME=mailtrap_username# MAIL_PASSWORD=mailtrap_password# MAIL_ENCRYPTION=tlsMAIL_DRIVER=smtpMAIL_HOST=smtp.sendgrid.netMAIL_PORT=587MAIL_USERNAME=sendgrid_usernameMAIL_PASSWORD=sendgrid_passwordMAIL_ENCRYPTION=tls在控制器中,我想在这样成功创建用户后发送邮件...use App\Mail\VerifyEmail;...use Illuminate\Support\Facades\Mail;public function register(Request $request){ // create and store new user record $user = User::create([ 'username' => $request->username, 'password' => bcrypt($request->password) ]); // send user email verification link Mail::to($user->username)->send(new VerifyEmail());}验证邮件.php<?phpnamespace App\Mail;use Illuminate\Bus\Queueable;use Illuminate\Mail\Mailable;use Illuminate\Queue\SerializesModels;use Illuminate\Contracts\Queue\ShouldQueue;class VerifyEmail extends Mailable{ use Queueable, SerializesModels; /** * Create a new message instance. * * @return void */ public function __construct() { // } /** * Build the message. * * @return $this */ public function build() { $from = 'support@fromus.com'; $name = 'custom name'; $subject = 'Welcome! Confirm Your Email'; return $this->from($from, $name) ->subject($subject) ->view('auth.verify'); }}按照电子邮件验证文档https://laravel.com/docs/5.8/verification#verification-routing我添加了Auth::routes(['verify' => true])这样的api.php文件<?php// Register routes for email verificationAuth::routes(['verify' => true]);Route::prefix('v1')->group(function () { // protected routes Route::middleware('auth:api')->group(function () { Route::get('products', 'ProductController@index'); // get products });});为什么我会收到Authentication required错误消息,我该如何解决?
1 回答
宝慕林4294392
TA贡献2021条经验 获得超8个赞
首先,我Auth::routes(['verify' => true])
从api.php
文件中删除并将其添加到web.php
. 然后我跑去php artisan config:cache
缓存对env
文件所做的更改。固定的
- 1 回答
- 0 关注
- 112 浏览
添加回答
举报
0/150
提交
取消