gpt4 book ai didi

php - Symfony swiftmailer 通过本地主机上的 smtp gmail openssl 错误

转载 作者:行者123 更新时间:2023-12-01 22:20:35 25 4
gpt4 key购买 nike

升级到 php 5.6 (mac os x sierra) 后,我无法在本地测试环境中发送邮件。

但遗憾的是,在 Symfony 中无法通过 swiftmailer 发送邮件。

这是错误:

[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

到目前为止我发现了什么:

因为 php 5.6 openssl 似乎是一个要求:http://php.net/manual/en/migration56.openssl.php

因为在更新之后我根本无法使用 file_get_contents 没有这个错误,所以我所做的是指定一个openssl.cafile=在我的 php ini 中,就像我在这里找到的:https://andrewyager.com/2016/10/04/php-on-macos-sierra-cant-access-ssl-data/

现在 file_get_contents 再次工作,但我无法通过 smtp 发送 swiftmailer 邮件。

这是我的 swiftmailer 配置:

swiftmailer:

transport:        "smtp"
host: "smtp.gmail.com"
username: "%mailer_user%"
password: "%mailer_password%"
auth_mode: login
port: 587
encryption: tls
delivery_address: "%mailer_delivery_address%"
spool: { type: memory }

我必须在任何其他地方向 symfony/swiftmailer 提供我的 cafile 吗?

我已经找到了:PHP - Swiftmailer using STARTTLS and self signed certificates但是像这样硬编码解决方案不是一种选择,因为我想部署代码库而不每次都更改它。我更愿意在系统层面解决这个问题。

最佳答案

看来,问题出在您在本地计算机上的自签名证书上。

您必须将以下内容添加到您的 config.yml(或者如果您希望在后续的 config_dev.yml 中将 test/dev 与 prod 分开):

swiftmailer:
# ... your other config
stream_options:
ssl:
allow_self_signed: true
verify_peer: false

这样它应该可以工作,并且您将开发环境和生产环境分开。

另请参阅此处:https://github.com/symfony/swiftmailer-bundle/tree/master/Tests/DependencyInjection/Fixtures/config/yml

关于php - Symfony swiftmailer 通过本地主机上的 smtp gmail openssl 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40378067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com