@@ -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
@@ -1308,7 +1308,7 @@ protected function appendAttachments(&$body, $boundary, $multipart = null)
13081308 . 'Content-Type: ' . $ attachment ['type ' ] . '; name=" ' . $ name . '" ' . $ this ->newline
13091309 . 'Content-Disposition: ' . $ attachment ['disposition ' ] . '; ' . $ this ->newline
13101310 . 'Content-Transfer-Encoding: base64 ' . $ this ->newline
1311- . ($ attachment ['cid ' ] === '' ? '' : 'Content-ID: < ' . $ attachment ['cid ' ] . '> ' . $ this ->newline )
1311+ . (isset ( $ attachment ['cid ' ]) && $ attachment [ ' cid ' ] !== '' ? 'Content-ID: < ' . $ attachment ['cid ' ] . '> ' . $ this ->newline : '' )
13121312 . $ this ->newline
13131313 . $ attachment ['content ' ] . $ this ->newline ;
13141314 }
@@ -1886,7 +1886,7 @@ protected function SMTPEnd()
18861886 */
18871887 protected function SMTPConnect ()
18881888 {
1889- if (is_resource ( $ this ->SMTPConnect )) {
1889+ if ($ this ->isSMTPConnected ( )) {
18901890 return true ;
18911891 }
18921892
@@ -1910,7 +1910,7 @@ protected function SMTPConnect()
19101910 $ this ->SMTPTimeout ,
19111911 );
19121912
1913- if (! is_resource ( $ this ->SMTPConnect )) {
1913+ if (! $ this ->isSMTPConnected ( )) {
19141914 $ this ->setErrorMessage (lang ('Email.SMTPError ' , [$ errno . ' ' . $ errstr ]));
19151915
19161916 return false ;
@@ -2227,7 +2227,7 @@ protected function mimeTypes($ext = '')
22272227
22282228 public function __destruct ()
22292229 {
2230- if ($ this ->SMTPConnect !== null ) {
2230+ if ($ this ->isSMTPConnected () ) {
22312231 try {
22322232 $ this ->sendCommand ('quit ' );
22332233 } catch (ErrorException $ e ) {
@@ -2284,4 +2284,16 @@ protected function setArchiveValues(): array
22842284
22852285 return $ this ->archive ;
22862286 }
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+ }
22872299}
0 commit comments