PHP - 使用 STARTTLS 和自签名证书的 Swiftmailer

标签 php smtp certificate swiftmailer self-signed

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

PHP 消息:PHP 警告:stream_socket_enable_crypto():SSL 操作失败,代码为 1。OpenSSL 错误消息: 错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证在第 97 行的 [..]/lib/classes/Swift/Transport/StreamBuffer.php 中失败 PHP 消息:PHP fatal error :在 [..]/lib/classes/Swift/Transport/EsmtpTransport.php:294 中未捕获异常“Swift_TransportException”,并显示消息“无法使用 TLS 加密进行连接”

我是否需要在某处添加我自己的证书才能使其被接受?或者这是一些 OpenSSL 配置错误?

最佳答案

Editor's note: disabling SSL verification has security implications. Without verification of the authenticity of SSL/HTTPS connections, a malicious attacker can impersonate a trusted endpoint (such as GitHub or some other remote Git host), and you'll be vulnerable to a Man-in-the-Middle Attack.

Be sure you fully understand the security issues before using this as a solution.

Swiftmailer 现已更新,包含此选项。现在可以使用 Swift_SmtpTransport 实例中的 setStreamOptions 方法来解决此问题,而无需编辑 swift 类。

$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 - 使用 STARTTLS 和自签名证书的 Swiftmailer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26896265/

相关文章:

smtp - Supabase 从自定义 SMTP 设置返回多个错误?

python - 从 python 脚本发送电子邮件

windows-8 - 如何使用 Windows 8 RT 的开发人员许可证手动签署 exe 文件

ssl - 我的软件应该如何处理 future 的 SSL 证书?

c# - 如何以编程方式为 WCF 服务创建自签名证书?

php - 在 Laravel 4 中缓存 View 输出

php - 如何使用 Ajax 函数从 php 服务器获取 session 变量? (PHP HTML JS Ajax)

php - MySQL/PHP...寻找可能简单的问题的答案

php - 如何在调用类的成员函数时自动调用函数?

.net - 如何在 .NET 中对 SMTP 进行身份验证?