How to Fix Laravel Email Issue

纵然是瞬间 提交于 2019-12-11 17:35:30

问题


I'm implementing Laravel 5.8 built-in Email Verification feature but unfortunately I couldn't figure the bug.

I've added the MustVerifyEmail interface in ,y User Model.

This is my .ENV file in Laravel. Same configuration I used in mail.php.

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME="<My user Name>"
MAIL_PASSWORD="<My Password>"
MAIL_ENCRYPTION=ssl


回答1:


You have to enable access to less secure apps in your google account security settings.




回答2:


For configuring gmail settings in laravel,

MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your_email_address@gmail.com
MAIL_PASSWORD=your_gmail_address_password
MAIL_FROM_ADDRESS=your_email_address@gmail.com
MAIL_FROM_NAME="YOUR_USER_NAME"
MAIL_ENCRYPTION=tls

Also update the following in mail.php

'pretend' => false,
    'stream' => [
        'ssl' => [
            'allow_self_signed' => true,
            'verify_peer' => false,
            'verify_peer_name' => false,
        ],
    ],

To test your configuration put this code on api.php

Route::get('/emailTest',function(){

    $emailData = [
        'from'      => 'admin_email@gmail.com',
        'email'     => 'user_email@gmail.com',
        'password'  => 'user_password',
    ];
    // "mails.toUser" : this is my email template in resources
    Mail::send('mails.toAdmin',['emailData' => $emailData],function($message) use ($emailData){
        $message->to($emailData['email'])
            ->from($emailData['from'])
            ->subject('New User Registration');
    });
});


来源:https://stackoverflow.com/questions/57836214/how-to-fix-laravel-email-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!