警告:stream_socket_enable_crypto():SSL操作失败,代码为1

时间:2014-11-23 12:32:52

标签: php apache ssl phpmailer freebsd

我遇到CSCart的问题,它无法通过谷歌帐户发送邮件。 要检查服务器配置或CSCart脚本中是否存在问题,我安装了干净的PHPMailer库并尝试使用示例脚本发送测试消息。 结果是一样的:

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 in [script path]/class.smtp.php on line 338    

来自控制台的OpenSSL连接运行良好。

FreeBSD 10.0,Apache24,php5.6。

我在谷歌找不到任何信息,现在我甚至不知道在哪个配置文件中搜索问题根。

3 个答案:

答案 0 :(得分:4)

这是由于PHP 5.6中新的默认验证策略。它没有在php.ini中设置;它是一个为fopen包装器或流上下文提供的选项。查看选项here,尤其是verify_peer。 PHPMailer允许您在smtpConnect()方法期间设置这些参数,但是没有选项将选项传递到smtpSend()方法,因此您需要将PHPMailer子类化以实现它。

您可能会发现另类更简单 - don't try to use a self-signed or unverifiable certificate

答案 1 :(得分:1)

有很多配置会导致出现此错误,但更常见的是您的系统配置设置不正确。要正确执行此操作,请按以下步骤操作:

  1. 检查您是否拥有OPENSSL的cacert.pem文件。如果你没有,请根据你的php版本从cacert.pem下载正确的版本,并将你的php.ini文件配置为" 2"

  2. 如果您有此文件,则必须在php.ini文件中查找并查看是否已在其中设置。为此:查找行:

    import string def intefer_shift(encrypted_textfile, language): index = 0 file_connector = open(encrypted_textfile,'r') data = file_connector.read() box =[] data = data.lower() file_connector.close() times = 0 #this for loop is designed to count the number of times items appear in file # this for loop is designed print each letter in the alphabet and tells how many times they appear for letter in string.ascii_lowercase: num = data.count(letter) print(letter, ':', num) intefer_shift('homework1.txt','English')

  3. 如果您找到具有特定地址的行,请查找该地址中的cacert.pem文件(如果找到),而不是使用cacert.pem文件完成。否则,您应该使用正确的地址。

答案 2 :(得分:0)

laRAVEL 5.4 ERROR中的

C:\ XAMPP \ htdocs中\ itis_​​db \厂商\ swiftmailer \ swiftmailer \ lib中\类\夫特\运输\ StreamBuffer.php

并在StreamBuffer.php

中找到此功能
private function _establishSocketConnection()

并将此两行粘贴到此函数

$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;

并重新加载浏览器并尝试再次运行您的项目。对我来说,我穿上这样:

private function _establishSocketConnection()
{
    $host = $this->_params['host'];
    if (!empty($this->_params['protocol'])) {
        $host = $this->_params['protocol'].'://'.$host;
    }
    $timeout = 15;
    if (!empty($this->_params['timeout'])) {
        $timeout = $this->_params['timeout'];
    }
    $options = array();
    if (!empty($this->_params['sourceIp'])) {
        $options['socket']['bindto'] = $this->_params['sourceIp'].':0';
    }

   $options['ssl']['verify_peer'] = FALSE;
    $options['ssl']['verify_peer_name'] = FALSE;

    $this->_stream = @stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options));
    if (false === $this->_stream) {
        throw new Swift_TransportException(
            'Connection could not be established with host '.$this->_params['host'].
            ' ['.$errstr.' #'.$errno.']'
            );
    }
    if (!empty($this->_params['blocking'])) {
        stream_set_blocking($this->_stream, 1);
    } else {
        stream_set_blocking($this->_stream, 0);
    }
    stream_set_timeout($this->_stream, $timeout);
    $this->_in = &$this->_stream;
    $this->_out = &$this->_stream;
}

希望你能解决这个问题.....