PHP - Swiftmailer使用STARTTLS和自签名证书 [英] PHP - Swiftmailer using STARTTLS and self signed certificates

查看:1346
本文介绍了PHP - Swiftmailer使用STARTTLS和自签名证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用STARTTLS发送包含php和swiftmailer的电子邮件,但我收到了证书错误。我有对SMTP服务器的root访问权限,并且使用的证书是自签名的。
我在两台机器上使用Debian(web服务器和smtp服务器)

I'm trying to send an email with php and swiftmailer, using STARTTLS, but I'm getting a certificate error. I have root access to the SMTP server, and the certificate used is self-signed. I'm using Debian on both machines (web server and smtp server)

PHP消息:PHP警告:stream_socket_enable_crypto SSL操作失败,代码1. OpenSSL错误消息:
错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败在[..] / lib / classes / Swift / Transport / StreamBuffer.php第97行
PHP消息:PHP致命错误:在[..] / lib / classes / Swift / Transport / EsmtpTransport.php中出现消息无法连接TLS加密的未捕获异常Swift_TransportException:

我需要在我们的地方添加自己的证书才能被接受吗?或者这是一些OpenSSL配置错误?

Do I need to add my own certificate somewhere to get it accepted? Or is this some OpenSSL configuration error?

推荐答案

Swiftmailer现在已更新为包含一个选项。现在可以使用 Swift_SmtpTransport 实例中的 setStreamOptions 方法而不是编辑swift类来解决。

Swiftmailer has now been updated to include an option for this. It can now be solved using the setStreamOptions method from your Swift_SmtpTransport instance rather than editing the swift class.

$transport = Swift_SmtpTransport::newInstance('smtp.server.com', 123, 'tls')
    ->setUsername('username')
    ->setPassword('password')
    ->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false)));

这篇关于PHP - Swiftmailer使用STARTTLS和自签名证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆