我是 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/