Skip to content
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

Error: Email SMTP may throw Uncaught ErrorException #3390

Closed
crustamet opened this issue Jul 23, 2020 · 10 comments · Fixed by #6184
Closed

Error: Email SMTP may throw Uncaught ErrorException #3390

crustamet opened this issue Jul 23, 2020 · 10 comments · Fixed by #6184
Assignees
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@crustamet
Copy link
Contributor

crustamet commented Jul 23, 2020

Hello guys i found an Uncaught ErrorException: fwrite():

Fatal error: Uncaught ErrorException: fwrite(): send of 6 bytes failed with errno=32 Broken pipe in /path/system/Email/Email.php:2019 
Stack trace: #0 [internal function]: 
CodeIgniter\Debug\Exceptions->errorHandler(8, 'fwrite(): send ...', '/path...', 2019, Array) #1 /path/system/Email/Email.php(2019): 
fwrite(Resource id #10, 'QUIT\r\n') #2 /path/system/Email/Email.php(1941): 
CodeIgniter\Email\Email->sendData('QUIT\r\n') #3 /path/system/Email/Email.php(2139): 
CodeIgniter\Email\Email->sendCommand('quit') #4 [internal function]: 
CodeIgniter\Email\Email->__destruct() #5 {main} thrown in /path/system/Email/Email.php on line 2019

When the configuration of the email is wrong this error appears almost in every case

@crustamet crustamet added the bug Verified issues on the current code behavior or pull requests that will fix them label Jul 23, 2020
@crustamet crustamet changed the title Bug: Email SMTP TLS config not working Error: Email SMTP configured wrong gives error Jul 23, 2020
@crustamet
Copy link
Contributor Author

Is this an intended error that we should see or it is a real Uncaught ErrorException ?

@paulbalandan
Copy link
Member

What wrong config did you make exactly?

From my Googling, this behavior is expected from SMTP servers and is not a framework bug. One use case where this will appear is when you have the wrong SMTP port. As I understand it, the server is assuming you as a spammer and closes the connection early, thus giving you that exception.

@crustamet
Copy link
Contributor Author

Yes exactly, sorry for not testing exactly which are the cases, but it seems when you put the wrong port, it gives you this Uncaught ErrorException.

But the problem is i don`t see it in a codeigniter manor error. it just outputs the error in the printDebuger() function i think.

Anyway it is not that a big of a problem the script continues to execute even if the error is written. I think, i never tested everything.

But yeah when you use SMTP and put a wrong port for me it output this error. So i thought it was some bug from codeigniter.
Maybe is still is because i already said i don't see it in a codeigniter error manor.

@paulbalandan
Copy link
Member

I'm sorry but was is manor error exactly?

@crustamet
Copy link
Contributor Author

crustamet commented Aug 1, 2020

with the Codeigniter Error Toolbar included, the error didnt appear anywhere until i put a die() after the email sending to check what was the problem.

@paulbalandan
Copy link
Member

Have you checked your writable/logs folder if this was logged?

@paulbalandan
Copy link
Member

Ideally, if there were errors in sending emails, these would be logged in your error logs in the writable folder. These will not stop script execution as the sending happens inside a try block.

@crustamet
Copy link
Contributor Author

yes it got logged.. anyway i think it got fixed with the new update for the email pull request

@ogeet
Copy link

ogeet commented Jun 19, 2022

Hello. I'm having same issue

Fatal error: Uncaught ErrorException: fwrite(): Send of 6 bytes failed with errno=10053 An established connection was aborted by the software in your host machine in C:\laragon\www\software\system\Email\Email.php:2022 
Stack trace: 
#0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(8, 'fwrite(): Send ...', 'C:\\laragon\\www\\...', 2022) 
#1 C:\laragon\www\software\system\Email\Email.php(2022): fwrite(Resource id #109, 'QUIT\r\n') 
#2 C:\laragon\www\software\system\Email\Email.php(1932): CodeIgniter\Email\Email->sendData('QUIT\r\n') 
#3 C:\laragon\www\software\system\Email\Email.php(2149): CodeIgniter\Email\Email->sendCommand('quit') 
#4 [internal function]: CodeIgniter\Email\Email->__destruct() 
#5 {main} thrown in C:\laragon\www\software\system\Email\Email.php on line 2022

How do i go about it please?

@kenjis kenjis added bug Verified issues on the current code behavior or pull requests that will fix them and removed bug Verified issues on the current code behavior or pull requests that will fix them labels Jun 20, 2022
@kenjis
Copy link
Member

kenjis commented Jun 20, 2022

@ogeet Try:

--- a/system/Email/Email.php
+++ b/system/Email/Email.php
@@ -2144,7 +2144,13 @@ class Email
     public function __destruct()
     {
         if (is_resource($this->SMTPConnect)) {
-            $this->sendCommand('quit');
+            try {
+                $this->sendCommand('quit');
+            } catch (ErrorException $e) {
+                $protocol = $this->getProtocol();
+                $method   = 'sendWith' . ucfirst($protocol);
+                log_message('error', 'Email: ' . $method . ' throwed ' . $e->getMessage());
+            }
         }
     }
 

@kenjis kenjis reopened this Jun 20, 2022
@kenjis kenjis changed the title Error: Email SMTP configured wrong gives error Error: Email SMTP may throw Uncaught ErrorException Jun 20, 2022
@kenjis kenjis self-assigned this Jun 24, 2022
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 a pull request may close this issue.

4 participants