php - 我如何在 php 中将 STARTTLS 与 swiftmailer 一起使用?

标签 php laravel email smtp swiftmailer

这是我的第一个问题,对我来说太简单了。

如何在 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/

相关文章:

mysql - Laravel 查询生成器分组

php - 在 Laravel 5.3 Blade 中渲染动态 anchor 标记

php - 从完整的数据过滤器年份中获取年份

PHP/MySQL 在 session 超时时更新数据库

php - Laravel 4 模型 : Confused about a pivot table case

c# - MailAddress:在邮件 header 中发现无效字符

c# - 使用 C# 发送经过身份验证的 SMTP

php - htaccess 为带或不带尾部斜杠的 url 添加 .html 扩展名

php - 插入选择 - 不起作用

css - 如何更改 Thunderbird 的默认链接 CSS?