简体   繁体   English

我无法使用gmail SMTP发送带有快速邮件的邮件

[英]I'm failing to send mail with swift mail using gmail SMTP

I am getting this error 我收到此错误

Expected response code 250 but got code "530", with message "530-5.5.1 Authentication Required. Learn more at\r\n
530 5.5.1  https://support.google.com/mail/?p=WantAuthError 14sm769143wmo.27 - gsmtp\r\n

I have used php artisan config:cache and restarted my server but i still get the error. 我使用了php artisan config:cache并重新启动了服务器,但是仍然出现错误。

Heres my config/mail.php details 这是我的config / 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', 'Example@gmail.com'),
            'name' => env('MAIL_FROM_NAME', 'Example'),
        ],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

      'username' => env('Example@gmail.com'),

        'password' => env('******'),

Heres my UserController 这是我的UserController

<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;


class UserController extends Controller
{

    public function sendMail()
    {


        \Mail::send('emails.welcome', array('Test'=>'Test User'),
        function($message) 
        {
            $message->from('Example@gmail.com', 'Your Application');
            $message->to('Example@gmail.com', 'Test')->subject('Your Reminder!');        
        });
        echo"Mail sent successfully...!";
    }
}

Here's my view file 这是我的查看文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h1>hello, {{{$Test}}}!</h1>
</body>
</html>

My .env file 我的.env文件

MAIL_DRIVER= smtp
MAIL_HOST= smtp.gmail.com
MAIL_PORT= 587
MAIL_USERNAME = Example@gmail.com
MAIL_PASSWORD = ******
MAIL_ENCRYPTION = tls

How can i get this to work?? 我怎样才能使它正常工作?

Set smtp details in .env file, not in config file. 在.env文件中而不是在配置文件中设置smtp详细信息。 see the code 看代码

env('MAIL_DRIVER', 'smtp')

so this env() function is getting data from .env file, so set your values there. 因此,此env()函数是从.env文件获取数据的,因此请在此处设置值。 not in config. 不在配置中。 or if u want to set in config file, set like this 或者如果您想在配置文件中设置,请像这样设置

'driver' => 'smtp',
'host' => 'smtp.gmail.com',

and so on. 等等。

Change your .env file: 更改您的.env文件:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=Example@gmail.com
MAIL_PASSWORD=******
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=Example@gmail.com

I think that port 587 and encryption tls can't be used again. 我认为端口587和加密tls不能再次使用。 maybe the tls certification is not valid 可能是tls认证无效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM