首页 > 解决方案 > 如何使用 swiftmailer .env 的特殊字符对密码进行编码

问题描述

我正在使用 Swiftmail 通过 gmail 发送电子邮件。我已经在我的 .env 中配置了 MAILER_URL。但是我的密码中有一个特殊字符。我读过当有特殊字符时您必须对密码进行编码,但我不知道如何。

# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=gmail://landabravo@gmail.com:landaB/24@localhost
###< symfony/swiftmailer-bundle ###```

标签: phpsymfony4swiftmailer

解决方案


需要使用RFC 3986对值进行编码。实际上,您可以使用 PHP urlencode()

所以值:landaB/24变为:landaB%2F24


推荐阅读