@@ -263,7 +263,7 @@ class Email
263
263
/**
264
264
* SMTP Connection socket placeholder
265
265
*
266
- * @var resource|null
266
+ * @var false| resource|null
267
267
*/
268
268
protected $ SMTPConnect ;
269
269
@@ -1886,7 +1886,7 @@ protected function SMTPEnd()
1886
1886
*/
1887
1887
protected function SMTPConnect ()
1888
1888
{
1889
- if (is_resource ( $ this ->SMTPConnect )) {
1889
+ if ($ this ->isSMTPConnected ( )) {
1890
1890
return true ;
1891
1891
}
1892
1892
@@ -1910,7 +1910,7 @@ protected function SMTPConnect()
1910
1910
$ this ->SMTPTimeout ,
1911
1911
);
1912
1912
1913
- if (! is_resource ( $ this ->SMTPConnect )) {
1913
+ if (! $ this ->isSMTPConnected ( )) {
1914
1914
$ this ->setErrorMessage (lang ('Email.SMTPError ' , [$ errno . ' ' . $ errstr ]));
1915
1915
1916
1916
return false ;
@@ -2227,7 +2227,7 @@ protected function mimeTypes($ext = '')
2227
2227
2228
2228
public function __destruct ()
2229
2229
{
2230
- if ($ this ->SMTPConnect !== null ) {
2230
+ if ($ this ->isSMTPConnected () ) {
2231
2231
try {
2232
2232
$ this ->sendCommand ('quit ' );
2233
2233
} catch (ErrorException $ e ) {
@@ -2284,4 +2284,16 @@ protected function setArchiveValues(): array
2284
2284
2285
2285
return $ this ->archive ;
2286
2286
}
2287
+
2288
+ /**
2289
+ * Checks if there is an active SMTP connection.
2290
+ *
2291
+ * @return bool True if SMTP connection is established and open, false otherwise
2292
+ */
2293
+ protected function isSMTPConnected (): bool
2294
+ {
2295
+ return $ this ->SMTPConnect !== null
2296
+ && $ this ->SMTPConnect !== false
2297
+ && get_debug_type ($ this ->SMTPConnect ) !== 'resource (closed) ' ;
2298
+ }
2287
2299
}
0 commit comments