bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
2.66k stars 446 forks source link

SMTP->send throws internal error #1188

Closed altayevrim closed 4 years ago

altayevrim commented 4 years ago

SMTP->send throws an internal error and dies when there is a connection problem. Is it possible to change it or add a parameter so we can bypass it just for checking? I mean if someone enters an invalid host, instead of dying it could return false with a silent error. So we can troubleshoot that easily without breaking our all system.

pauljherring commented 4 years ago

I think this is one for the list.

You probably need something similar to (anonymised from my own code - may not be perfect...):

$e = onerror(function($f3){ $f3->set('HALT',FALSE); return true; });// trap smtp errors
if ($this->smtp->send($this->body, true) === TRUE){
    // mail sent
}else{
    // handle error
}
altayevrim commented 4 years ago

It's nice but I actually don't want to edit f3 error handlers. I think it is still possible to edit the handlers and only do that for 500 errors but I think it would be good to add another parameter. Thanks for the idea though I am planning to create this :+1:

pauljherring commented 4 years ago

It only needs to be changed for that instance - restore it afterwards (if it actually needs to be - in my code that's typically the last substantial thing to run on any particular invocation of the software.)

altayevrim commented 4 years ago

I am using only one instance, but I think only before checking smtp I can change the error handlers. So it will be restored automatically. Thanks!