技术 · 2022 年 8 月 29 日

MAILER_DSN邮件设置

升级了新版Symfony,打开前台页面会出错,提示:DSN is invalid
原来旧版里的邮箱默认是MAILER_URL,新版默认的是MAILER_DSN。
搞了半天终于明白,MAILER_DSN需要将邮箱地址和密码里的特殊字符进行转码才行。

例如:
你的字符串:
MAILER_DSN=smtp://alice@example.com:password@smtp.example.com
需变成:
MAILER_DSN=smtp://alice%40example.com:password@smtp.example.com

注意密码里的部分特殊字符也需要改变。

例如你的密码是:BA&E_34*3O8P
需要转码成:BA%26E_34%2A3O8P
后面的服务器信息不需要转码。可以使用在线转码工具:https://www.urlencoder.org/

另外,在环境Ubuntu22.04,PHP8.0,Postfix下,使用本地邮件服务器localhost:25会出现:”lost connection after STARTTLS from localhost”的提示。
实在没有办法,只能使用绝对域名地址了,例如邮件服务器的指向域名是smtp.example.com:
MAILER_DSN=smtp://alice%40example.com:password@smtp.example.com:25?auth_mode=plain