Skip to content

Bug: SMTP TLS encryption forces ssl:// connection on port 587 (STARTTLS broken) #1726

Description

Description
When selecting TLS as the SMTP encryption method in Admin > Advanced Parameters > E-mail,
QloApps incorrectly forces a direct SSL connection (ssl://) instead of using STARTTLS.
This causes the connection to fail on port 587 with errors like:

  • "wrong version number"
  • "SSL routines: wrong version number"

Root Cause
In classes/Mail.php, the $isTls variable is set to true for ANY encryption
that is not "off" — including "tls". However, in Symfony Mailer's EsmtpTransport,
passing true for $tls forces a direct SSL/SMTPS connection (ssl://),
which is only correct for port 465.

For port 587 with STARTTLS, $isTls must be false so EsmtpTransport
starts an unencrypted connection and upgrades it via STARTTLS automatically.

Affected code (classes/Mail.php ~line 145 and ~line 504):

// CURRENT (BUGGY) CODE:
if (!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])
    || Tools::strtolower($configuration['PS_MAIL_SMTP_ENCRYPTION']) === 'off'
) {
    $isTls = false;
} else {
    $isTls = true; // ← This incorrectly forces ssl:// for TLS/STARTTLS
}

**Fix :**
// CORRECT CODE:
if (isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])
    && Tools::strtolower($configuration['PS_MAIL_SMTP_ENCRYPTION']) === 'ssl'
) {
    $isTls = true;  // Direct SSL — correct for port 465
} else {
    $isTls = false; // STARTTLS — correct for port 587
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions