Skip to content

fix: SMTP connection resource validation in Email class destructor - #9648

Merged
samsonasik merged 6 commits into
codeigniter4:developfrom
michalsn:fix/email-destruct
Jul 30, 2025
Merged

fix: SMTP connection resource validation in Email class destructor#9648
samsonasik merged 6 commits into
codeigniter4:developfrom
michalsn:fix/email-destruct

Conversation

@michalsn

Copy link
Copy Markdown
Member

Description
This PR fixes a bug where the destructor was checking $this->SMTPConnect !== null to validate SMTP connections.

However, fclose() creates closed resources that are not null, which led to unnecessary cleanup attempts on already-closed connections.

When the SMTPKeepAlive option is false (the default), the quit command is called before the destructor is reached.

Fixes#9647

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsnmichalsn added the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 29, 2025
@michalsn

Copy link
Copy Markdown
MemberAuthor

No tests are provided, as I'm not sure how this could be tested effectively.

However, since this is a regression from v4.6.1, I believe it's acceptable without tests in this case.

Comment threadsystem/Email/Email.php Outdated
@samsonasik
samsonasik merged commit 2ec5eff into codeigniter4:developJul 30, 2025
50 checks passed
@samsonasik

Copy link
Copy Markdown
Member

Thank you @michalsn

@michalsn
michalsn deleted the fix/email-destruct branch July 31, 2025 06:37
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugVerified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: fwrite(): supplied resource is not a valid stream resource

3 participants

@michalsn@samsonasik@paulbalandan