@@ -263,7 +263,7 @@ class Email
263263 /**
264264 * SMTP Connection socket placeholder
265265 *
266- * @var resource|null
266+ * @var false| resource|null
267267 */
268268 protected $ SMTPConnect ;
269269
@@ -1313,7 +1313,7 @@ protected function appendAttachments(&$body, $boundary, $multipart = null)
13131313 . 'Content-Type: ' . $ attachment ['type ' ] . '; name=" ' . $ name . '" ' . $ this ->newline
13141314 . 'Content-Disposition: ' . $ attachment ['disposition ' ] . '; ' . $ this ->newline
13151315 . 'Content-Transfer-Encoding: base64 ' . $ this ->newline
1316- . ($ attachment ['cid ' ] === '' ? '' : 'Content-ID: < ' . $ attachment ['cid ' ] . '> ' . $ this ->newline )
1316+ . (isset ( $ attachment ['cid ' ]) && $ attachment [ ' cid ' ] !== '' ? 'Content-ID: < ' . $ attachment ['cid ' ] . '> ' . $ this ->newline : '' )
13171317 . $ this ->newline
13181318 . $ attachment ['content ' ] . $ this ->newline ;
13191319 }
@@ -1891,7 +1891,7 @@ protected function SMTPEnd()
18911891 */
18921892 protected function SMTPConnect ()
18931893 {
1894- if (is_resource ( $ this ->SMTPConnect )) {
1894+ if ($ this ->isSMTPConnected ( )) {
18951895 return true ;
18961896 }
18971897
@@ -1915,7 +1915,7 @@ protected function SMTPConnect()
19151915 $ this ->SMTPTimeout ,
19161916 );
19171917
1918- if (! is_resource ( $ this ->SMTPConnect )) {
1918+ if (! $ this ->isSMTPConnected ( )) {
19191919 $ this ->setErrorMessage (lang ('Email.SMTPError ' , [$ errno . ' ' . $ errstr ]));
19201920
19211921 return false ;
@@ -2259,7 +2259,7 @@ protected function mimeTypes($ext = '')
22592259
22602260 public function __destruct ()
22612261 {
2262- if ($ this ->SMTPConnect !== null ) {
2262+ if ($ this ->isSMTPConnected () ) {
22632263 try {
22642264 $ this ->sendCommand ('quit ' );
22652265 } catch (ErrorException $ e ) {
@@ -2316,4 +2316,16 @@ protected function setArchiveValues(): array
23162316
23172317 return $ this ->archive ;
23182318 }
2319+
2320+ /**
2321+ * Checks if there is an active SMTP connection.
2322+ *
2323+ * @return bool True if SMTP connection is established and open, false otherwise
2324+ */
2325+ protected function isSMTPConnected (): bool
2326+ {
2327+ return $ this ->SMTPConnect !== null
2328+ && $ this ->SMTPConnect !== false
2329+ && get_debug_type ($ this ->SMTPConnect ) !== 'resource (closed) ' ;
2330+ }
23192331}
0 commit comments