Skip to content

Commit 39c5df6

Browse files
authored
Merge pull request #7883 from kenjis/fix-email-tls
fix: Email library forces to switch to TLS when setting port 465
2 parents ed5d07e + 2d0fa2e commit 39c5df6

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

app/Config/Email.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ class Email extends BaseConfig
5656
public bool $SMTPKeepAlive = false;
5757

5858
/**
59-
* SMTP Encryption. Either tls or ssl
59+
* SMTP Encryption.
60+
*
61+
* @var string '', 'tls' or 'ssl'. 'tls' will issue a STARTTLS command
62+
* to the server. 'ssl' means implicit SSL. Connection on port
63+
* 465 should set this to ''.
6064
*/
6165
public string $SMTPCrypto = 'tls';
6266

system/Email/Email.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ class Email
113113
/**
114114
* SMTP Encryption
115115
*
116-
* @var string Empty, 'tls' or 'ssl'
116+
* @var string '', 'tls' or 'ssl'. 'tls' will issue a STARTTLS command
117+
* to the server. 'ssl' means implicit SSL. Connection on port
118+
* 465 should set this to ''.
117119
*/
118120
public $SMTPCrypto = '';
119121

@@ -1868,9 +1870,13 @@ protected function SMTPConnect()
18681870

18691871
$ssl = '';
18701872

1873+
// Connection to port 465 should use implicit TLS (without STARTTLS)
1874+
// as per RFC 8314.
18711875
if ($this->SMTPPort === 465) {
18721876
$ssl = 'tls://';
1873-
} elseif ($this->SMTPCrypto === 'ssl') {
1877+
}
1878+
// But if $SMTPCrypto is set to `ssl`, SSL can be used.
1879+
if ($this->SMTPCrypto === 'ssl') {
18741880
$ssl = 'ssl://';
18751881
}
18761882

user_guide_src/source/libraries/email.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Email properties. Then save the file and it will be used automatically.
6666
You will NOT need to use the ``$email->initialize()`` method if
6767
you set your preferences in the config file.
6868

69+
.. _email-ssl-tls-for-smtp:
70+
6971
SSL versus TLS for SMTP Protocol
7072
--------------------------------
7173

@@ -85,7 +87,7 @@ will upgrade the channel to use encryption using the ``STARTTLS`` SMTP command.
8587

8688
Upgrading a connection on port 465 may or may not be supported by the server, so the
8789
``STARTTLS`` SMTP command may fail if the server does not allow it. If you set the port to 465,
88-
you should try to leave the ``SMTPCrypto`` setting blank since the communication is
90+
you should try to set the ``SMTPCrypto`` to an empty string (``''``) since the communication is
8991
secured using TLS from the start and the ``STARTTLS`` is not needed.
9092

9193
If your configuration requires you to connect to port 587, you should most likely set
@@ -115,14 +117,15 @@ Preference Default Value Options Descript
115117
**SMTPHost** No Default None SMTP Server Address.
116118
**SMTPUser** No Default None SMTP Username.
117119
**SMTPPass** No Default None SMTP Password.
118-
**SMTPPort** 25 None SMTP Port. (If set to 465, TLS will be used for the connection
119-
regardless of SMTPCrypto setting.)
120+
**SMTPPort** 25 None SMTP Port. (If set to ``465``, TLS will be used for the connection
121+
regardless of ``SMTPCrypto`` setting.)
120122
**SMTPTimeout** 5 None SMTP Timeout (in seconds).
121123
**SMTPKeepAlive** false true or false (boolean) Enable persistent SMTP connections.
122-
**SMTPCrypto** No Default tls or ssl SMTP Encryption. Setting this to "ssl" will create a secure
123-
channel to the server using SSL and "tls" will issue a
124+
**SMTPCrypto** tls tls, ssl, or empty string SMTP Encryption. Setting this to ``ssl`` will create a secure
125+
channel to the server using SSL, and ``tls`` will issue a
124126
``STARTTLS`` command to the server. Connection on port 465 should
125-
set this to blank.
127+
set this to an empty string (``''``). See also
128+
:ref:`email-ssl-tls-for-smtp`.
126129
**wordWrap** true true or false (boolean) Enable word-wrap.
127130
**wrapChars** 76 Character count to wrap at.
128131
**mailType** text text or html Type of mail. If you send HTML email you must send it as a complete web

0 commit comments

Comments
 (0)