OpenCart

Solving OpenCart 4.x SMTP Mail Issues: A Comprehensive Troubleshooting Guide

Setting up SMTP mail in OpenCart, especially with self-hosted VPS mail servers, can often be a frustrating experience. The OpenCart community forum frequently sees discussions around "Connection refused," "Connection timed out," and "SSL wrong version number" errors. These issues can halt critical store communications, from order confirmations to customer service replies, severely impacting your e-commerce operations.

This insight article analyzes a recent forum topic where a user, mr_webshop_manager, struggled with SMTP configuration in OpenCart v4.x. After trying various configurations and troubleshooting steps, they ultimately found a workaround by switching to a third-party SMTP delivery service. We'll delve into the common pitfalls highlighted in this discussion and provide actionable, in-depth troubleshooting steps to help you overcome your OpenCart 4.x SMTP challenges.

OpenCart mail settings alongside server terminal commands for diagnosing SMTP connection issues.
OpenCart mail settings alongside server terminal commands for diagnosing SMTP connection issues.

The Frustration of OpenCart SMTP: A Real-World Scenario

The forum thread perfectly illustrates the typical journey of an OpenCart user facing SMTP issues. mr_webshop_manager started with a self-hosted mail server on their VPS, confident in their settings which worked for other mail clients. However, OpenCart consistently failed to connect, throwing errors like:

2026-05-07 07:18:00 - PHP Warning: fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:error:0A00010B:SSL routines::wrong version number in /var/www/www.mysite.nl/www/public/system/library/mail/smtp.php on line 143

This initial error, wrong version number, points directly to an SSL/TLS protocol mismatch. As the discussion progressed, other errors emerged:

  • Connection refused (111): Indicating the mail server actively rejected the connection.
  • Connection timed out (110): Suggesting the server didn't respond within the allotted time.

Despite verifying firewall rules and trying different ports (25, 465, 587) with various prefixes (ssl://, tls://, none), the problem persisted. This scenario is incredibly common and highlights the nuanced interplay between OpenCart's PHP environment, the mail server's configuration, and network settings.

Common OpenCart 4.x SMTP Mail Challenges

The discussion highlights several recurring themes when OpenCart struggles to connect to an SMTP server:

  • SSL/TLS Protocol Mismatches: The initial error encountered by mr_webshop_manager, error:0A00010B:SSL routines::wrong version number, is a classic sign that the OpenCart client (via PHP's fsockopen()) and the mail server cannot agree on a common SSL/TLS protocol version. This usually means one side is trying to use an older, deprecated protocol (like TLSv1.0 or SSLv3) while the other only supports newer, more secure ones (TLSv1.2, TLSv1.3), or vice-versa.
  • Incorrect Port & Prefix Combinations: Using the wrong port for a given encryption type (e.g., SSL on port 25) or incorrect prefix (ssl://, tls://, or none) is a frequent misconfiguration. The prefix tells PHP how to initiate the encrypted connection.
  • Server-Side Firewall vs. Mail Server Configuration: An open firewall port (as shown by firewall-cmd) does not automatically mean the mail server is listening on that port or configured to accept connections from the OpenCart application. The firewall might allow traffic, but the mail service itself might not be running or configured to bind to that specific port.
  • Connection Refused/Timed Out: These errors (Connection refused (111), Connection timed out (110)) typically indicate different network issues. "Connection refused" means the server actively rejected the connection attempt, often due to the service not running, incorrect configuration, or an internal server firewall. "Connection timed out" means no response was received from the server within the specified period, suggesting network blockage, a heavily loaded server, or an incorrect hostname/IP.
  • PHP fsockopen() Behavior: Differences in how PHP's underlying network functions interact with mail servers compared to dedicated mail clients (like an iPhone's mail app or a desktop client) can lead to unique issues. PHP's OpenSSL extension version, system-wide OpenSSL libraries, and PHP configuration can all play a role.

Detailed Troubleshooting Steps for OpenCart 4.x SMTP

Based on the community discussion and common best practices, here’s a guide to diagnosing and resolving your OpenCart 4.x SMTP issues:

1. Verify Mail Server Configuration and Listening Ports

Do not rely solely on firewall rules. You need to confirm your mail server (e.g., Postfix, Exim, Sendmail) is actively listening on the ports and protocols you intend to use. For example, if you plan to use SSL on port 465, ensure the mail server is configured for it. The forum user ADD Creative rightly pointed out that "That just your firewall, doesn't mean your mail server is listening."

You can use commands like netstat -tulnp | grep -E '465|587|25' or ss -tulnp | grep -E '465|587|25' on your VPS to see if services are listening on these ports. Look for output indicating a service (e.g., master for Postfix, exim for Exim) listening on the desired port. If nothing is listed, your mail server isn't configured or running correctly for that port. Also, check your mail server's logs (e.g., /var/log/mail.log or /var/log/maillog on Linux) for any errors related to binding to ports or starting services.

2. Correct Port and Encryption Protocol Mapping

Ensure your OpenCart mail settings align with your mail server's configuration. This is one of the most common configuration errors:

  • SSL (Secure Sockets Layer): Typically uses Port 465 with the ssl:// prefix in the hostname (e.g., ssl://mail.mysite.nl). This is often referred to as implicit SSL, where the SSL handshake begins immediately upon connection. While functional, it's generally considered less flexible than explicit TLS.
  • TLS (Transport Layer Security): Typically uses Port 587 with the tls:// prefix in the hostname (e.g., tls://mail.mysite.nl). This is the modern, recommended approach for authenticated SMTP. It uses STARTTLS, meaning the connection starts unencrypted and then upgrades to TLS.
  • Unencrypted/Legacy: Uses Port 25 with no prefix. This port is primarily for server-to-server communication and is often blocked by ISPs or hosting providers due to spam concerns. It should generally be avoided for outgoing mail from applications like OpenCart, especially with authentication. mr_webshop_manager initially tried ssl://mail.mysite.nl:25, which is an incorrect combination, as SSL typically uses 465.

Always double-check your mail provider's documentation for the exact recommended settings.

3. Address SSL/TLS Version Compatibility Issues

The error error:0A00010B:SSL routines::wrong version number indicates a mismatch. This is usually a server-side issue or a mismatch with your PHP environment's OpenSSL capabilities. Your mail server might be configured to use older or newer TLS versions that OpenCart's PHP environment doesn't support by default, or vice versa. You might need to:

  • Update PHP's OpenSSL libraries: Ensure your PHP installation is up-to-date and its OpenSSL extension is linked to a modern OpenSSL library. You can check your PHP's OpenSSL version with php -i | grep SSL.
  • Configure your mail server: Adjust your mail server's configuration to support a wider range of TLS protocols (e.g., TLSv1.2, TLSv1.3) that are compatible with your PHP version. For Postfix, this might involve editing /etc/postfix/main.cf and setting parameters like smtpd_tls_mandatory_protocols or smtpd_tls_protocols.
  • Test your server's SSL/TLS capabilities: Use openssl s_client -connect mail.mysite.nl:465 -tls1_2 or -tls1_3 from your server's command line to diagnose which TLS versions your mail server supports. If it connects successfully, it will show certificate details; if not, it will indicate a handshake failure.

4. Increase Connection Timeout

When encountering "Connection timed out" errors, increasing the connection timeout can sometimes help, especially if the server is slow to respond, there's network latency, or the mail server is under heavy load. ADD Creative suggested this, advising to "Try making your timeout 30 or 60."

In OpenCart 4.x, you can typically adjust the Mail Timeout setting in your administration panel:

  1. Go to System > Settings.
  2. Edit your store.
  3. Navigate to the Mail tab.
  4. Locate the Mail Timeout field and increase its value (e.g., to 30 or 60 seconds). The default is often 5 seconds.

While the exact line might vary, the underlying PHP code in system/library/mail/smtp.php uses this value in the fsockopen() call:

$this->socket = fsockopen($hostname, $port, $errno, $errstr, $this->timeout);

Increasing this value gives the server more time to establish a connection before OpenCart gives up.

5. Test with External SMTP Delivery Services

As mr_webshop_manager discovered, sometimes the most efficient solution is to offload mail delivery to a dedicated third-party SMTP service. "After filling in some details and adapting the dns record for the domain (adding some CNAMES forwarding to their servers I guess) it worked in a split second." Services like SendGrid, Mailgun, SMTP2GO, Amazon SES, or even a properly configured Google Workspace (Gmail) SMTP can be more reliable and easier to set up, circumventing complex self-hosted mail server issues.

These services specialize in email deliverability, often come with robust APIs, and handle the intricacies of mail server configuration, SPF, DKIM, and DMARC records for you. Setting them up usually involves:

  • Registering an account and obtaining SMTP credentials (hostname, port, username, password).
  • Adding specific DNS records (like SPF, DKIM, and sometimes CNAMEs for tracking) to your domain to authorize the service to send emails on your behalf.

This approach significantly reduces the burden of managing a mail server and often improves email deliverability rates, preventing your transactional emails from landing in spam folders.

Beyond the Basics: Essential Checks

  • Check OpenCart System Logs: Always examine your OpenCart error logs (located at system/storage/logs/error.log) for detailed PHP errors. These logs often provide more context than what's displayed on the frontend.
  • PHP Mail Function: While OpenCart offers a "Mail" option (which uses PHP's built-in mail() function), it's generally not recommended for production stores. It lacks authentication, often leads to emails being marked as spam, and provides minimal error reporting. SMTP is always the superior choice for reliability.
  • DNS Records (SPF, DKIM, DMARC): Even if your connection issues are resolved, ensure your domain's DNS records include proper SPF, DKIM, and DMARC entries. These are crucial for email authentication and deliverability, telling receiving mail servers that your emails are legitimate and not spoofed.
  • Hosting Environment: If you're on shared hosting, your control over mail server configurations and firewall rules might be limited. In such cases, a third-party SMTP service is almost always the best option. On a VPS, you have full control but also full responsibility for configuration.

Conclusion

Troubleshooting OpenCart SMTP issues, particularly with self-managed mail servers, requires a systematic approach, checking both OpenCart's configuration and the mail server's setup. The errors encountered by mr_webshop_manager are classic examples of the challenges involved. By methodically verifying mail server configurations, ensuring correct port and protocol mapping, addressing SSL/TLS version compatibility, and adjusting timeouts, you can often resolve these frustrating issues.

However, as the forum discussion concluded, leveraging robust third-party SMTP services often provides a quick, reliable, and highly scalable solution, saving valuable time and ensuring critical store communications are delivered without a hitch. Whichever path you choose, a clear understanding of the underlying technology will empower you to keep your OpenCart store communicating effectively.

Share:

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools