2016-11-02 80 views
1

升级到php 5.6(mac os x sierra)之后,我无法在本地测试环境中发送邮件。Symfony swiftmailer通过本地主机上的smtp gmail openssl错误

但令人伤心的是,通过在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我的凭证档案错误?

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

+1

请注明您使用的OpenSSL版本。还请显示设置OpenSSL使用的上下文的代码。它应该类似于OpenSSL wiki上的[SSL/TLS Client](https://wiki.openssl.org/index.php/SSL/TLS_Client)。 – jww

回答

3

看来,这个问题是自签名证书,因为你是在本地机器上。

您必须添加以下到您的config.yml(或者,如果你喜欢从PROD在随后config_dev.yml分开测试/开发):

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

这样,它应该工作,你必须开发和prod env分开。

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

+0

非常感谢。我想避免这种情况,但使用config_dev.yml似乎是一个好主意! –

相关问题