在Symfony 4.3中,引入了新的电子邮件程序。
请参阅此处:
对于SMTP传输,已确定ENV变量中的DSN具有以下格式:
MAILER_DSN=smtp://user:[email protected]
编写DSN时如何处理用户名和密码中的特殊字符?
让我们假设凭据是:
username: [email protected]
password: the:password:is:difficult
这种设置很可能会失败:
MAILER_DSN=smtp://[email protected]:the:password:is:[email protected]
我应该如何编码/转义?正确的DSN是什么?
您可以对值进行urlencode。
[邮件程序组件中有一个测试(Tests / Transport / DsnTest.php),指示它应与编码值一起使用。
Test: gmail smtp with urlencoded user and pass
因此您可以使用在线编码器转换您的值(例如https://www.urlencoder.org/)
您的字符串:
MAILER_DSN=smtp://[email protected]:the:password:is:[email protected]
成为:
MAILER_DSN=smtp://alice%40example.com:the%3Apassword%3Ais%[email protected]