【问题标题】:Symfony swiftmailer via smtp gmail on localhost openssl errorSymfony swiftmailer 通过 smtp gmail 在 localhost openssl 错误
【发布时间】:2017-03-15 15:42:30
【问题描述】:

升级到 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 }

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

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

【问题讨论】:

  • 请说明您使用的 OpenSSL 版本。还请显示设置 OpenSSL 使用的上下文的代码。它应该类似于 OpenSSL wiki 上的 SSL/TLS Client

标签: php symfony swiftmailer pyopenssl


【解决方案1】:

它在 swiftmailer 配置中对我有用:

swiftmailer:
...
  encryption: null
...

【讨论】:

    【解决方案2】:

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

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

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

    这样它应该可以工作,并且你已经将 dev 和 prod env 分开了。

    请看这里:https://github.com/symfony/swiftmailer-bundle/tree/master/Tests/DependencyInjection/Fixtures/config/yml

    【讨论】:

    • 非常感谢。我想避免这种情况,但使用 config_dev.yml 似乎是个好主意!
    【解决方案3】:

    您可以创建自己的服务来实现此行为。 检查这个解决方案,你也可以为 Swift_SmtpTransport 创建自己的工厂:

    https://github.com/swiftmailer/swiftmailer/issues/544#issuecomment-220103233

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多