接触laravel不久开始写项目,期间一个关于邮件通知的功能,颇受折磨(源于自己的傻逼)
先看报错信息:
production.ERROR: Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required^M
" {"userId":7,"exception":"[object] (Swift_TransportException(code: 530): Expected response code 250 but got code \"530\", with message \"530 5.7.1 Authentication required^M
\" at /root/www/项目根目录/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:457)
错误信息很明确
Authentication required
但是依然没想过来是自己配置的问题,因为本地运行完全没问题,上线服务器之后出现此问题,百度,Google后得出如下几个解决方案:
php artisan config:clear or php artisan config:cache
其实就是更新配置缓存
如果你用的是非ssl,使用25端口和阿里云服务器,那应该注意服务器端口的开放(建议用465端口ssl)
配置如下:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.163.com
MAIL_PORT=465
MAIL_USERNAME=me@163.com
MAIL_PASSWORD=NYOPAIWMHGFPOZRG
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=me@163.com
MAIL_FROM_NAME='测试'
最终突然想起来是因为 .env文件是不加入git的,所以线上配置文件并没有更新,scp 上传.env,发送成功