Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 30, 2025

Conversation

michalsn
Copy link
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

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

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.

@samsonasik samsonasik merged commit 2ec5eff into codeigniter4:develop Jul 30, 2025
50 checks passed
@samsonasik
Copy link
Member

Thank you @michalsn

@michalsn michalsn deleted the fix/email-destruct branch July 31, 2025 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified 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