php - 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;
}
解决方案
推荐阅读
- python - Statsmodels 的 Logit.fit_regularized 一直在运行
- javascript - 在 Angular 组件中使用 Tippy.js
- python - 如何将每行中打印的内容连接到 csv?
- python - 搜索行,拉取特定数据
- python - 如何在 apache 上部署 vuejs/flask 项目
- sql - 投射数组
>>进入地图 > - javascript - 试图理解 browser.elementIdText 命令
- python - python - 从 S3(在内存中)解压缩 csv 文件,然后对其进行迭代
- mongodb - 如何在使用 mongodb 时正确处理 promise?
- c# - 缺少编译器所需的成员 Microsoft.CSharp.RuntimeBinder.Binder.Convert