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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42574375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:38:39  来源:igfitidea点击:

laravel Expected response code 250 but got code "530"

phplaravel-5.1

提问by mendz

Im trying to Mail in Laravel 5.1

我试图在 Laravel 5.1 中发送邮件

my mail.php code is

我的mail.php代码是

 return [
     'driver' => env('MAIL_DRIVER', 'smtp'),
     'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
     'port' => env('MAIL_PORT', 587),
     'from' => ['address' => '[email protected]', '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),

 ];

my .env file is

我的 .env 文件是

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=null

my function to email is

我的电子邮件功能是

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

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

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

Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. l188sm21749863pfl.28 - gsmtp" error appears every time i call my function.

预期响应代码为 250,但得到代码“530”,消息为“530 5.7.0 必须先发出 STARTTLS 命令。l188sm21749863pfl.28 - gsmtp”每次调用我的函数时都会出现错误。

回答by Amarja

I had the same problem. I changed,

我有同样的问题。我变了,

MAIL_ENCRYPTION=null to 
MAIL_ENCRYPTION=tls 

php artisan config:cache

and it worked.

它奏效了。

回答by Winston Fale

you need to enable your 2 step verification from gmail account.

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

https://myaccount.google.com/security

https://myaccount.google.com/security

then use the generated key from there to your ENV_PASSWORD instead your real password.

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

回答by Hassan Azimi

Use SSLand port 465like this:

像这样使用SSL和移植465

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=12345678
MAIL_ENCRYPTION=ssl

100% will work.

100% 会起作用。

回答by alireza

Go to Manage Your Google Account page then at the Security tab go to App passwords and get new random code. use it at .env file and replace it with an email password.

转到管理您的 Google 帐户页面,然后在安全选项卡上转到应用密码并获取新的随机代码。在 .env 文件中使用它并用电子邮件密码替换它。

回答by Serdar De?irmenci

You should restart the artisan after those changes. That was the issue for me.

您应该在这些更改后重新启动工匠。这就是我的问题。

回答by m.y.m

After enabling logging to the mail from the less secured devices, make sure that .envfile contains the following configurations:

启用从安全性较低的设备登录邮件后,请确保该.env文件包含以下配置:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD="your_passwrod_here"
MAIL_ENCRYPTION=tls

Make sure that your password is rounded by the double quotes "".

确保您的密码被双引号四舍五入""

Make sure that your mail.phpfile contains configurations like the following:

确保您的mail.php文件包含如下配置:

'from' => [
    'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
    'name' => env('MAIL_FROM_NAME', 'your_email'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),

And don't forget to close the server and run php artisan config:clearto clear the configuration cache.

并且不要忘记关闭服务器并运行php artisan config:clear以清除配置缓存。

This worked for me

这对我有用

回答by Meysam

change your MAIL_ENCRYPTION = null to MAIL_ENCRYPTION = ssl or MAIL_ENCRYPTION = tls. i had this issue before and changing to MAIL_ENCRYPTION = tls worked for me. also make sure that your mail settings in config\mail.php is the same as .env file

将您的 MAIL_ENCRYPTION = null 更改为 MAIL_ENCRYPTION = ssl 或 MAIL_ENCRYPTION = tls。我之前遇到过这个问题,改为 MAIL_ENCRYPTION = tls 对我有用。还要确保 config\mail.php 中的邮件设置与 .env 文件相同