Symfony swiftmailer通过smtp gmail on localhost openssl错误

Kla*_*yer 2 php pyopenssl swiftmailer symfony

升级到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
Run Code Online (Sandbox Code Playgroud)

我到现在才发现:

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

因为在更新后我没有能够使用file_get_contents而没有这个错误,所以我做的是 在我的php ini中指定一个 openssl.cafile =就像我在这里找到的那​​样:https://andrewyager.com/2016/10/ 04/PHP-上的MacOS-Sierra公司-斜面存取SSL的数据/

现在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 }
Run Code Online (Sandbox Code Playgroud)

我是否必须在symfony/swiftmailer的任何其他地方提供我的咖啡馆?

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

mat*_*tlm 6

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

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

swiftmailer:
    # ... your other config
    stream_options:
      ssl:
        allow_self_signed: true
        verify_peer: false
Run Code Online (Sandbox Code Playgroud)

这样它应该工作,你有dev和prod env分开.

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