【问题标题】:Unable to send email s using Laravel无法使用 Laravel 发送电子邮件
【发布时间】:2019-08-05 14:57:11
【问题描述】:

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

Tinker 返回此错误:

 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),依此类推。有意义吗?

感谢您的任何建议。

【问题讨论】:

  • 此错误看起来您的凭据有误。您的密码是否包含# 字符? dotenv 库最近更新了,之后它可能会考虑将任何内容作为评论(所以用引号括住密码)
  • 是的! psw 包含“#”!!!!!!!哈哈!!!!我要测试一个新的psw!
  • 谢谢!!!有用!!!我欠你一杯啤酒!!!我快疯了!谢谢!!!!

标签: laravel authentication smtp


【解决方案1】:

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

解决方法是引用密码:

MAIL_PASSWORD="my#secret"

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

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

【讨论】:

  • 谢谢特拉维斯!你让我开心:)
猜你喜欢
  • 2018-07-08
  • 1970-01-01
  • 1970-01-01
  • 2017-01-16
  • 2016-04-15
  • 2016-01-27
  • 2015-08-24
  • 2018-08-12
相关资源
最近更新 更多