首页 > 解决方案 > stream_socket_enable_crypto():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14090086:SSL 例程:ssl3_get_server_certificate:

问题描述

使用带有 ssl/tls 的 PHPMailer 发送邮件时出现以下错误。请帮忙。

内部服务器错误 stream_socket_enable_crypto():SSL 操作失败,代码为 1。 OpenSSL 错误消息:错误:14090086:SSL 例程:ssl3_get_server_certificate:certificate verify failed Web 服务器处理您的请求时发生内部错误。请联系网站管理员报告此问题。


function sendMail($mailArray){
    //require 'PHPMailerAutoload.php';

    //initialize mail inputs
    $toAddress = (isset($mailArray['toAddress']) &&  $mailArray['toAddress']!= '') ? $mailArray['toAddress'] : '';
    $fromAddress = (isset($mailArray['fromAddress']) &&  $mailArray['fromAddress']!= '') ? $mailArray['fromAddress'] : 'TestEmail@domain.com';
    $fromName = (isset($mailArray['fromName']) &&  $mailArray['fromName']!= '') ? $mailArray['fromName'] : 'Registration Verification';
    $replyTo = (isset($mailArray['replyTo']) &&  $mailArray['replyTo']!= '') ? $mailArray['replyTo'] : '';
    $replyToName = (isset($mailArray['replyToName']) &&  $mailArray['replyToName']!= '') ? $mailArray['replyToName'] : '';
    $recipientName = (isset($mailArray['recipientName']) &&  $mailArray['recipientName']!= '') ? $mailArray['recipientName'] : '';
    $subject = (isset($mailArray['subject']) &&  $mailArray['subject']!= '') ? $mailArray['subject'] : 'Compliance Registration Verification';
    $message = (isset($mailArray['message']) &&  $mailArray['message']!= '') ? $mailArray['message'] : '';
    $cc = (isset($mailArray['cc']) &&  $mailArray['cc']!= '') ? $mailArray['cc'] : '';
    $bcc = (isset($mailArray['bcc']) &&  $mailArray['bcc']!= '') ? $mailArray['bcc'] : '';
    $attachmentFilePath = (isset($mailArray['attachmentFilePath']) &&  $mailArray['attachmentFilePath']!= '') ? $mailArray['attachmentFilePath'] : '';
    $attachmentFileName = (isset($mailArray['attachmentFileName']) &&  $mailArray['attachmentFileName']!= '') ? $mailArray['attachmentFileName'] : '';

    $mail = new PHPMailer;

    $mail->isSMTP();    // Set mailer to use SMTP
    $mail->Host = 'mail.domain.com';  // Specify main and backup server
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    //$mail->SMTPSecure = 'ssl';                         // Enable encryption, 'ssl' also accepted
    $mail->SMTPSecure = 'tls';
    $mail->Username = 'TestEmail@domain.com';
    $mail->Password = 'password';
    $mail->Port = '587';

    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
            //,'cafile' => '/etc/ssl/ca_cert.pem'
        )
    );


    $mail->From = $fromAddress;
    $mail->FromName = $fromName;
    if($recipientName != ""){
        $mail->addAddress($toAddress, $recipientName);  // Add a recipient
    }else{
        $mail->addAddress($toAddress);               // Name is optional
    }
    $mail->addReplyTo($replyTo, $replyToName);
    $mail->addCC($cc);
    $mail->addBCC($bcc);

    $mail->WordWrap = 50;                                 // Set word wrap to 50 characters
    $mail->addAttachment($attachmentFilePath);         // Add attachments
    $mail->addAttachment($attachmentFilePath, $attachmentFileName);    // Optional name
    $mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = $subject;
    $mail->Body    = $message;

    //uncomment to send email
    if(!$mail->send()) {
      // echo 'Message could not be sent.';
       //echo 'Mailer Error: ' . $mail->ErrorInfo;
       return false;
    }

    return true;
}

标签: phpsslphpmailertls1.2

解决方案


推荐阅读