laravel 预期响应代码 250,但得到代码“530”

2022-08-30 22:30:56

我试图在Laravel 5.1中邮寄

我的邮件.php代码是

 return [
     'driver' => env('MAIL_DRIVER', 'smtp'),
     'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
     'port' => env('MAIL_PORT', 587),
     'from' => ['address' => 'myemail@gmail.com', 'name' => 'sample'],
     'encryption' => env('MAIL_ENCRYPTION', 'tls'),
     'username' => env('MAIL_USERNAME'),
     'password' => env('MAIL_PASSWORD'),
     'sendmail' => '/usr/sbin/sendmail -bs',
     'pretend' => env('MAIL_PRETEND', false),

 ];

我的 .env 文件是

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=null

我的电子邮件功能是

public function sendEmailVerification()
{
    $user = $this->user;//retrieved by $request->user() in __construct

    Mail::send('emails.verifyemail', ['user' => $user], function ($m) use ($user) {
        $m->from('myemail@gmail.com, 'sample');

        $m->to($user->email, $user->name)->subject('Verify Email');
    });
}

每次调用我的函数时都会出现错误。

预期的响应代码 250,但收到代码“530”,并带有消息“530 5.7.0 必须首先发出 STARTTLS 命令”。l188sm21749863pfl.28 - gsmtp”


答案 1

我遇到了同样的问题。我变了,

MAIL_ENCRYPTION=null to 
MAIL_ENCRYPTION=tls 

php artisan config:cache

它奏效了。


答案 2

您需要从gmail帐户启用两步验证。

https://myaccount.google.com/security

然后从那里使用生成的密钥到您的ENV_PASSWORD而不是您的真实密码。


推荐