Symfony swiftmailer通过smtp gmail在本地主机openssl错误


Symfony swiftmailer via smtp gmail on localhost openssl error

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

但遗憾的是,通过swiftmailer在Symfony中发送邮件不工作。

错误:

[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?

我已经发现了这个:PHP - Swiftmailer使用STARTTLS和自签名证书但是像这样的硬编码解决方案不是一个选择,因为我想部署代码库,而不是每次都改变它。我倾向于在系统级别上解决这个问题。

问题似乎出在您在本地机器上的自签名证书上。

您必须在您的配置中添加以下内容。Yml(或者如果您喜欢在随后的config_dev.yml中将test/dev与prod分开):

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

这样应该可以工作,并且dev和prod环境是分开的。

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

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

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

它在swiftmailer配置中为我工作:

swiftmailer:
...
  encryption: null
...