这是我的第一个问题,对我来说太简单了。
如何在 php 中将 STARTTLS 与 swiftmailer 一起使用?
我目前使用的是在 PHP 7.3 上运行的 Laravel 7.x。
我需要连接到 Office365 SMTP 服务器,不幸的是它只支持 STARTTLS。 由于另一家公司的基础设施,我无法使用 Office365 以外的其他提供商,因此我的选择有限。
我的问题是,当我将 STARTTLS 作为邮件加密并尝试通过 SMTP 服务器连接/发送邮件时,我收到以下错误:
[2020-06-25 11:15:21] stage.ERROR: Connection could not be established with host smtp.office365.com :stream_socket_client(): unable to connect to starttls://smtp.office365.com:587 (Unable to find the socket transport "starttls" - did you forget to enable it when you configured PHP?) {"userId":1,"exception":"[object] (Swift_TransportException(code: 0): Connection could not be established with host smtp.office365.com :stream_socket_client(): unable to connect to starttls://smtp.office365.com:587 (Unable to find the socket transport "starttls" - did you forget to enable it when you configured PHP?) at /home/forge/censoreddomain.com/releases/20200615132510/src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:269)
我的 .env 配置邮件部分:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.office365.com
MAIL_PORT=587
MAIL_USERNAME=XXXX@XXXX.se
MAIL_PASSWORD=XXXXXXXtXVF
MAIL_ENCRYPTION=starttls
最佳答案
尝试将“MAIL_ENCRYPTION=starttls”更改为“MAIL_ENCRYPTION=tls”
关于php - 我如何在 php 中将 STARTTLS 与 swiftmailer 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62577544/