Getting the following error when sending mail using PHPMailer with ssl/tls. Please help.
Internal Server Error stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed An internal error occurred while the Web server was processing your request. Please contact the webmaster to report this problem.
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;
}