laravel - 无法使用 Laravel 发送电子邮件

标签 laravel authentication smtp

我是 Laravel 新手,我正在尝试配置邮件。我的 .env 文件配置为:

MAIL_DRIVER=SMTP
MAIL_HOST=vserv.******.***
MAIL_PORT=587
MAIL_USERNAME=admin@******.***
MAIL_PASSWORD=*********   <--- (9 chars lengh)
MAIL_ENCRYPTION=TLS

对于我的邮件测试,我使用 Tinker:

>php artisan tinker
>>> Mail::send('mails.contact',[], function($message) { $message->to('sergio@******.****')->subject('Testing email'); });

在测试之前,我将缓存刷新为:

>php artisan config:cache
Configuration cache cleared!
Configuration cached successfully!

修补程序返回此错误:

 Swift_TransportException with message 'Failed to authenticate on SMTP server with username "admin@******.***" using 3 possible authenticators. Authenticator CRAM-MD5 returned Swift_TransportException: Expected response code 235 but got code "535", with message "535 5.7.8 Error: authentication failed: authentication failure 
" in ****/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:457

服务器端,邮件日志有错误:

Mar 14 16:47:13 vserv plesk_saslauthd[21227]: failed mail authenticatication attempt for user 'admin@******.***' (password len=8)

注意:我在 env 中使用的密码是 9 个字符,但在错误消息中始终少 1 个字符!如果我输入错误的 10 个字符长度的密码,则会显示错误(密码 len=9)等等。有道理吗?

感谢您的任何建议。

最佳答案

该错误表明您的用户名或密码错误。在本例中,密码字符串中有一个 # 字符,这会导致密码的其余部分被解释为注释。

解决办法是引用密码:

MAIL_PASSWORD="my#secret"

如果它曾经可以工作但现在不再工作,可能是因为 Laravel 5.8 包含了 dotenv 的更新版本改变行为的库:

https://laracasts.com/discuss/channels/laravel/beware-in-env-files

关于laravel - 无法使用 Laravel 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55167181/

相关文章:

java - GWT-RPC 还是 RequestFactory 用于身份验证?

c# - 有没有办法在 ASP.NET 中将身份验证从一个 Web 应用程序持久保存到另一个嵌套的 Web 应用程序?

php - 在 float LARAVEL 上调用成员函数 addEagerConstraints()

Laravel 从多个表中获取数据

c# - 使用 C# 以编程方式登录 Microsoft Online 网站

C# - SMTP Gmail 在发送时挂起。第一次工作

delphi - IdSMTP(独立组件)SSL 在 smtp.live.com 上不可用

laravel - laravel无法识别为内部或外部命令

php - MySQL 全文连字符和大括号返回错误(原为 : PDO prepared statement not doing its job?)

smtp - 发送网格 : Free plan vs Lite plan?