XF 1.4 PHP 5.6 Bounce Handle IMAP error

MattW

Well-known member
Using XF 1.4 RC1, after upgrading to PHP5.6, the bounce handle can't access the dedicated mail boxes

Code:
Error Info
Zend_Mail_Protocol_Exception: cannot connect to host; error = (errno = 0 ) - library/Zend/Mail/Protocol/Imap.php:100
Generated By: Unknown Account, 12 minutes ago
Stack Trace
#0 /home/www/mattwservices.co.uk/public/library/Zend/Mail/Storage/Imap.php(273): Zend_Mail_Protocol_Imap->connect('178.32.50.171', 993, 'SSL')
#1 /home/www/mattwservices.co.uk/public/library/XenForo/Model/EmailBounce.php(292): Zend_Mail_Storage_Imap->__construct(Array)
#2 /home/www/mattwservices.co.uk/public/library/XenForo/Deferred/EmailBounce.php(19): XenForo_Model_EmailBounce->openBounceHandlerConnection()
#3 /home/www/mattwservices.co.uk/public/library/XenForo/Model/Deferred.php(256): XenForo_Deferred_EmailBounce->execute(Array, Array, 7.9999978542328, '')
#4 /home/www/mattwservices.co.uk/public/library/XenForo/Model/Deferred.php(390): XenForo_Model_Deferred->runDeferred(Array, 7.9999978542328, '', false)
#5 /home/www/mattwservices.co.uk/public/library/XenForo/Model/Deferred.php(335): XenForo_Model_Deferred->_runInternal(Array, NULL, '', false)
#6 /home/www/mattwservices.co.uk/public/deferred.php(23): XenForo_Model_Deferred->run(false)
#7 {main}
Request State
array(3) {
  ["url"] => string(40) "https://mattwservices.co.uk/deferred.php"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(4) {
    ["_xfRequestUri"] => string(31) "/threads/picture-dump.66/page-3"
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfToken"] => string(8) "********"
    ["_xfResponseType"] => string(4) "json"
  }
}

Nothing else has changed, and I can connect with openssl

Code:
[root@host nginx]# openssl s_client -connect 178.32.50.171:993
CONNECTED(00000003)
depth=3 C = SE, O = AddTrust AB, OU = AddTrust External TTP Network, CN = AddTrust External CA Root
verify return:1
depth=2 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Certification Authority
verify return:1
depth=1 C = GB, ST = Greater Manchester, L = Salford, O = COMODO CA Limited, CN = COMODO RSA Domain Validation Secure Server CA
verify return:1
depth=0 OU = Domain Control Validated, OU = PositiveSSL, CN = cpanel.mattwservices.co.uk
verify return:1
 
PHP 5.6 adds some features regarding SSL certificate validation. It's possible that your cert isn't trusted by PHP (there are some configuration options around this in php.ini, I believe). You can disable cert validation if needed.

That said, this is one of these really annoying cases where no PHP error was actually returned by fsockopen. You can try this to see if any errors are generated:
Code:
ini_set('display_errors', true);
var_dump(fsockopen('178.32.50.171', 993, $errno, $errstr, 30));
var_dump($errno);
var_dump($errstr);
 
It's just test code. You can stick it in a new PHP script and run it to see what the output is. (Zend Framework suppresses an error from fsockopen here so it may be masking a real message.).
 
I think I've actually fixed it. Dovecote doesn't work with ipv6, and my server is connecting to my other server which runs mail. It's trying ipv6 first, so I was using the IP address rather than the FQDN. I've turned ipv6 off on the mail server, and set it back to be the FQDN in the email settings.
 
Hey @MattW, I'm having the same exact problem, I just moved to new VPS and everything is setup correctly the only error I see is this one, can please tell me how to disable ipv6, also is there any cons of doing that?
 
I have disabled the ipv6 by adding the flowing lines to the file /etc/sysctl.conf:

Code:
# to disable IPv6 on all interfaces system wide
net.ipv6.conf.all.disable_ipv6 = 1

# to disable IPv6 on a specific interface (e.g., eth0, lo)
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv6.conf.eth0.disable_ipv6 = 1

Then run command:
Code:
sudo sysctl -p /etc/sysctl.conf

Hope the issues doesn't appear anymore.
 
You might want to check that postfix / sendmail is still functioning, as you need to specify the protocol for ipv4 and restart the service if you disable ipv6.
 
You might want to check that postfix / sendmail is still functioning, as you need to specify the protocol for ipv4 and restart the service if you disable ipv6.

I'm using mandrill with bd mail, I have tested it and it's working, thanks for the tip. ;)
 
@MattW Unfortunately the problem still persist.

@Mike I have tried the code you suggested and this was the result:

Code:
resource(2) of type (stream) int(0) string(0) ""



Here's the full error:

Code:
Error Info
Zend_Mail_Protocol_Exception: cannot connect to host; error = Connection refused (errno = 111 ) - library/Zend/Mail/Protocol/Imap.php:100
Generated By: Unknown Account, 22 minutes ago
Stack Trace
#0 /home/nginx/domains/domain.com/public/library/Zend/Mail/Storage/Imap.php(273): Zend_Mail_Protocol_Imap->connect('server.domain.c...', 143, false)
#1 /home/nginx/domains/domain.com/public/library/XenForo/Model/EmailBounce.php(292): Zend_Mail_Storage_Imap->__construct(Array)
#2 /home/nginx/domains/domain.com/public/library/XenForo/Deferred/EmailBounce.php(19): XenForo_Model_EmailBounce->openBounceHandlerConnection()
#3 /home/nginx/domains/domain.com/public/library/XenForo/Model/Deferred.php(294): XenForo_Deferred_EmailBounce->execute(Array, Array, 7.9999978542328, '')
#4 /home/nginx/domains/domain.com/public/library/XenForo/Model/Deferred.php(428): XenForo_Model_Deferred->runDeferred(Array, 7.9999978542328, '', false)
#5 /home/nginx/domains/domain.com/public/library/XenForo/Model/Deferred.php(373): XenForo_Model_Deferred->_runInternal(Array, NULL, '', false)
#6 /home/nginx/domains/domain.com/public/deferred.php(23): XenForo_Model_Deferred->run(false)
#7 {main}
Request State
array(3) {
  ["url"] => string(30) "https://domain.com/deferred.php"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(4) {
    ["_xfRequestUri"] => string(22) "/forums/gta-series.36/"
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfToken"] => string(8) "********"
    ["_xfResponseType"] => string(4) "json"
  }
}
 
To those coming from Google like me:
If you're using SSL/TLS encryption, then the connection issue may be caused by having a too recent OpenSSL version. The Zend Client constructs a URI starting with ssl://, which does not seem to be working with new'ish OpenSSL anymore.

Solution: Append to your library/config.php
Code:
$config['ssltransport'] = 'tls';

This will fix not only outgoing IMAP but also HTTPS connections (sitemap ping). Tested on XF 1.5.24 with PHP 7.3 and OpenSSL 1.1.1k.

Switching the IMAP encryption option from SSL to TLS does not yield the expected result. I'm suspecting option "TLS" means "use STARTTLS" and option "SSL" means "use implicit SSL on connect" (or implicit TLS, if you apply the config change above). If you connect to IMAP port 993, you'll usually want implicit SSL/TLS.
 
Last edited:
Top Bottom