Platform: Ubuntu14.04 + xampp 5.5.24 \ 5.6.8 + openssl
Error message while sending an email from 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 /opt/lampp/htdocs/Sentrifugo_2.0/install/PHPMailer/class.smtp.php on line 270
on few blogs i have read that we can allow insecure connections via the SMTPOptions and achieve it by subclassing the SMTP class with the following:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
I would really appreciate if anyone can support in confirming where should i be configuring this as i have already searched the class.smtp.php and class.phpmailer.php files but couldnt find verify_peer .
Also, on line 270 i found the following code in class.smtp.php:
/**
* Initiate a TLS (encrypted) session.
* @access public
* @return bool
*/
public function startTLS()
{
if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
return false;
}
// Begin encrypted connection
if (!stream_socket_enable_crypto(
$this->smtp_conn,
true,
STREAM_CRYPTO_METHOD_TLS_CLIENT
)) {
return false;
}
return true;
}
Please suggest - thanks in advance
This is covered in the PHPMailer troubleshooting guide.
You're getting things a bit mixed up. In older versions of PHPMailer, you could only fix this by subclassing to pass in the ssl settings, but now you can do it via the code you posted:
This sets the
SMTPOptions
property of PHPMailer, which is passed to thestream_socket_client
function. There is noverify_peer
property in PHPMailer itself - it's a setting within the ssl properties of stream contexts in PHP.When
startTLS()
is called, the stream has already had the context attached to it, so whenstream_socket_enable_crypto
gets called, it will make use of the ssl properties set on the stream when it was created.Remember that when you choose to go this route of suppressing certificate verification, you are compromising your security.