I get the following error in log file:
fsockopen(): Failed to enable crypto /www/okr.loc/www/system/libraries/Email.php
and email could not be send.
I have PHP version 5.6.30 installed on server.
Since version 5.6.30, the protection of the SSL protocol has been improved.
To fix this, I downloaded library from the latest version Codeinteger and replace function
_smtp_connect().
Replace file
system/libraries/Email.php
with same one from downloaded latest Codeinteger 3.1.5 (There is fixed one more mistake).
Now, open
system/libraries/Email.php from your installation, and replace function
[php]/**
* SMTP Connect
*
* @return string
*/
protected function _smtp_connect()
{
if (is_resource($this->_smtp_connect))
{
return TRUE;
}
$ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : '';
$this->_smtp_connect = fsockopen($ssl.$this->smtp_host,
$this->smtp_port,
$errno,
$errstr,
$this->smtp_timeout);
if ( ! is_resource($this->_smtp_connect))
{
$this->_set_error_message('lang:email_smtp_error', $errno.' '.$errstr);
return FALSE;
}
stream_set_timeout($this->_smtp_connect, $this->smtp_timeout);
$this->_set_error_message($this->_get_smtp_data());
if ($this->smtp_crypto === 'tls')
{
$this->_send_command('hello');
$this->_send_command('starttls');
$crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
if ($crypto !== TRUE)
{
$this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data());
return FALSE;
}
}
return $this->_send_command('hello');
}[/php]
with this
[php]/**
* SMTP Connect
*
* @return string
*/
protected function _smtp_connect()
{
if (is_resource($this->_smtp_connect))
{
return TRUE;
}
$ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : '';
$streamContext = stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
]);
$this->_smtp_connect = stream_socket_client($ssl.$this->smtp_host.':'.$this->smtp_port,
$errno,
$errstr,
$this->smtp_timeout,
STREAM_CLIENT_CONNECT,
$streamContext);
if ( ! is_resource($this->_smtp_connect))
{
$this->_set_error_message('lang:email_smtp_error', $errno.' '.$errstr);
return FALSE;
}
stream_set_timeout($this->_smtp_connect, $this->smtp_timeout);
$this->_set_error_message($this->_get_smtp_data());
if ($this->smtp_crypto === 'tls')
{
$this->_send_command('hello');
$this->_send_command('starttls');
$crypto = stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
if ($crypto !== TRUE)
{
$this->_set_error_message('lang:email_smtp_error', $this->_get_smtp_data());
return FALSE;
}
}
return $this->_send_command('hello');
}[/php]
Now sending emails works without errors.
Here I just turned off checking the self-signed certificate.