【问题标题】:PHP Warning: stream_socket_enable_crypto(): SSL operation failed with code 1PHP 警告:stream_socket_enable_crypto():SSL 操作失败,代码为 1
【发布时间】:2018-03-07 15:02:43
【问题描述】:

我在尝试使用 PHPMailer 配置和发送邮件时收到以下警告:

PHP Warning:  stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

我查看了其他解决方案,但没有一个有效。以下是一些细节:

  1. 我的证书(来自letsencrypt)是有效的,至少在我的Nginx 配置中是这样。我的 WordPress 网站服务安全,没有错误。我的 PHP 版本是 7.0.xx

  2. 我尝试将证书文件位置添加到php.ini,但它警告加载流失败,即使地址正确。这是我尝试过的(除其他外):

    openssl.capath = "/etc/letsencrypt/live/example.org/" 这会导致 与上面完全相同的错误。

    我也试过: openssl.cafile = "/etc/letsencrypt/live/example.org/fullchain.pem" 但收到警告:PHP Warning:failed loading cafile stream

我的 PHP 邮件配置(位于我的 wordpress 函数文件中)如下所示:

        $phpmailer->Host = 'mail.example.org';
        $phpmailer->SMTPAuth = true;
        $phpmailer->Port = 587;
        $phpmailer->Username = 'myadminaccount@example.org';
        $phpmailer->Password = 'mypassword';
        $phpmailer->SMTPSecure = "tls";
        $phpmailer->From = "myadminaccount@example.org";
        $phpmailer->FromName = "MY Admin Account";

正如我所说,我已经尝试了网站上其他地方的各种解决方案,但都没有奏效。我很困惑,因为我的本地证书(以及邮件服务器的证书)都是有效的。

我真的不想像其他地方建议的那样关闭对等验证,但如果必须的话,我想我会的。

【问题讨论】:

  • 您好,请问您使用的是哪个版本的 PHP?
  • 如果 PHP 版本 >= 5.6 设置更改,如果您没有 stackoverflow.com/questions/31460941/… 问候,您可以在此处找到示例。
  • 对不起,我应该提到它是 PHP 7.0,我会在上面添加它。
  • 我相信 cacert 的正确变量不是“default_cert_file”,而是“ini_cafile”,让我们试试吧:)。
  • 你能说得更具体些吗?尝试什么以及在什么文件中?

标签: php wordpress ssl nginx


【解决方案1】:

UGH 解决方案相当简单,而且超出了我上面写的内容。我正在使用 switch case 来检查以确保我的服务器正确,如下所示:

switch ($_SERVER['HTTP_HOST']) {
        case 'https://example1.org':     
        // Set the hostname of the mail server
        $phpmailer->Host = 'mail.example1.org';

我需要省略https。所以改成:

switch ($_SERVER['HTTP_HOST']) {
        case 'example1.org':     
        // Set the hostname of the mail server
        $phpmailer->Host = 'mail.example1.org'; 

让它工作!我觉得自己像个傻瓜,但我希望这对其他人有帮助。

【讨论】:

    猜你喜欢
    • 2015-01-21
    • 1970-01-01
    • 2017-11-09
    • 2015-08-13
    • 1970-01-01
    • 2021-05-14
    • 2019-03-02
    • 1970-01-01
    • 2015-04-27
    相关资源
    最近更新 更多