php Laravel 5:发送电子邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31378357/
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-25 22:24:57  来源:igfitidea点击:

Laravel 5: Sending Email

phpemailsmtplaravel-5

提问by Saani

I am trying to send an email in laravel application. Here is my .envfile:

我正在尝试在 Laravel 应用程序中发送电子邮件。这是我的.env文件:

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

And here is the Mail::sendmethod:

这是Mail::send方法:

Mail::send('email', ['name' => "EE"], function($m){
            $m->to('[email protected]', 'Malik')->subject('Subjet of the email');
        });

And here is the error:

这是错误:

Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. s16sm7748968wib.16 - gsmtp"

Any help?

有什么帮助吗?

回答by Saani

Well, I got it. Infact the email was not authenticated because that email required a mobile phone authentication after login. changing to other email address that required just login credentials, it worked.

嗯,我明白了。事实上,该电子邮件未通过身份验证,因为该电子邮件在登录后需要手机身份验证。更改为仅需要登录凭据的其他电子邮件地址,它起作用了。

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

回答by Tarunn

GMail SMTP requires encryption. Try changing setting as following.

GMail SMTP 需要加密。尝试更改设置如下。

 MAIL_PORT=465
 MAIL_ENCRYPTION=ssl

回答by Jozsef Csiky

I made the following mistake: I did not actually include the

我犯了以下错误:我实际上没有包括

'encryption' => env('MAIL_ENCRYPTION'),

to the array return in mail.php. I did include my host, port, username and password in the mail.php but not the encryption method (the encryption method I only included in the .env file), so trying out these mentioned solutions did bring a change in the error messages outcome, created a bigger confusion, but none solved the problem. Hope this helps someone!

到mail.php 中的数组返回。我确实在 mail.php 中包含了我的主机、端口、用户名和密码,但没有包含加密方法(我只包含在 .env 文件中的加密方法),所以尝试这些提到的解决方案确实改变了错误消息结果,造成了更大的混乱,但没有人解决问题。希望这可以帮助某人!

回答by Yallison Gabriel Reis

If the above comments do not work, try clearing the cache:

如果以上注释不起作用,请尝试清除缓存:

php artisan cache:clear
php artisan config:clear

回答by jialu yao

maybe port error , you can look this web laravel or lumen send email

也许端口错误,你可以看看这个 web laravel 或 lumen 发送电子邮件