在Laravel 5.7中,验证电子邮件后发送电子邮件是一个常见的需求。下面是一个完善且全面的答案:
在Laravel 5.7中,验证电子邮件后发送电子邮件可以通过以下步骤实现:
composer create-project --prefer-dist laravel/laravel email-verification
cd email-verification
php artisan make:auth
use Illuminate\Support\Facades\Mail;
use App\Mail\EmailVerification;
protected function registered(Request $request, $user)
{
$this->sendEmailVerification($user);
return redirect($this->redirectPath());
}
protected function sendEmailVerification($user)
{
$verificationUrl = URL::temporarySignedRoute(
'verification.verify', Carbon::now()->addMinutes(60), ['id' => $user->id]
);
Mail::to($user->email)->send(new EmailVerification($verificationUrl));
}
php artisan make:mail EmailVerification
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
public $verificationUrl;
public function __construct($verificationUrl)
{
$this->verificationUrl = $verificationUrl;
}
public function build()
{
return $this->view('emails.verification')
->with([
'verificationUrl' => $this->verificationUrl,
]);
}
<p>请点击以下链接验证您的电子邮件:</p>
<a href="{{ $verificationUrl }}">{{ $verificationUrl }}</a>
php artisan make:auth
Auth::routes(['verify' => true]);
use Illuminate\Contracts\Auth\MustVerifyEmail;
class User extends Authenticatable implements MustVerifyEmail
{
// ...
}
php artisan vendor:publish --tag=laravel-mail
至此,你已经完成了在Laravel 5.7中验证电子邮件后发送电子邮件的过程。当用户注册后,系统会自动发送一封包含验证链接的电子邮件给用户,用户点击链接后即可完成电子邮件验证。
推荐的腾讯云相关产品:腾讯云邮件推送(https://cloud.tencent.com/product/ses)
希望以上回答能够满足你的需求,如果还有其他问题,请随时提问。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云