【发布时间】:2020-01-12 00:03:03
【问题描述】:
我正在尝试在 symfony 中使用 swiftmailer 和 office365 服务器注册后发送一封确认电子邮件。我已经尝试过所有遇到的主机、端口和加密类型的组合。
目前我的 .env 文件包含这一行:
MAILER_URL=smtp://smtp.office365.com:587?encryption=ssl&auth_mode=login&username="myusername@mycompany.com"&password="mypassword"
*注意:我使用“”作为我的用户名和密码,因为它们包含特殊字符,并且我在某处读到这可能会导致 MAILER_URL 出现问题。
我的 swiftmailer.yaml 文件包含以下内容:
swiftmailer:
url: '%env(MAILER_URL)%'
stream-options:
ssl:
allow_self_signed : true
verify_peer: false
最后,我在控制器中使用此代码发送电子邮件:
$message = (new \Swift_Message('Referral tool registration'))
->setFrom('myusername@mycompany.com')
->setTo('test@gmail.com')
->setBody(
$this->renderView(
'email/notification/user_registered.html.twig',
['firstName' => $user->getFirstName(),
'lastName' => $user->getLastName()
]
),
'text/html'
);
$mailer->send($message);
使用当前选择的主机、端口和加密,我得到:"Connection could not be established with host smtp.office365.com [ #0]"
更新:当我输入 telnet smtp.office365.com 587 我得到一个有效的响应,所以我认为问题与网络无关,端口没有被阻塞。
【问题讨论】:
-
你检查邮件地址是否被正确解析了吗?既然你提到了双引号,我可以想象它们可能会在某个时候被转义。
-
@dbrumann 我不认为双引号有什么不同,当我删除它们并对特殊字符进行编码时,我得到了同样的错误
标签: php symfony office365 symfony4 swiftmailer