The way to enable email verification functionality in Laravel (>= 5.7) is as follows:
1. Model User preparation
Implement the MustVerifyEmail contract.
app/User.php
class User extends Authenticatable
change to:
class User extends Authenticatable implements MustVerifyEmail
2. Database table field
Table users
must contain an email_varified_at
column.
3. Routing
Add verify
option to the Auth::routes
method in order to activate the Auth\VerificationController
.
app/routes/web.php
auth::routes(['verify' => true]);
4. .env configuration
Check the .env
file configuration.
5. Default mail host: using Mailtrap.io as mail host
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=xxx
MAIL_PASSWORD=xxx
MAIL_ENCRYPTION=null
Option 1: using Google Mail SMTP server as mail host:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xxxxxxx@gmail.com
MAIL_PASSWORD=xxxxxxxxxx
MAIL_ENCRYPTION=tls
Note: The “low security application access” of your Google account must be enable.
And Google will send you a notice and suggest not to enable it for security reason.
Option 2: using Mailgun
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=xxxxxxx@gmail.com
MAIL_PASSWORD=xxxxxxxxx
MAIL_ENCRYPTION=null
Note: Need to join a pay plan.
6. Views
Make sure app/resources/views/auth/verify.blade.php
exists.
7. Where to Redirect after verifying Emails
We can modify the route in VerificationController
.
app/Http/Controllers/Auth/VerificationController.php
protected $redirectTo = '/home';
No comments:
Post a Comment