Dennis Spohr

Send out email on exceptions

6 posts in this topic

Hi all,



it's possible to send out an email for fatal errors (for example a syntax-error).

It would be nice to get also an email in case of an unhandled exception. There could be a situation of an wrong upload and exceptions on the live-page.

Is this possible?

Also it could be a very handy feature to be able to choose specific logs which are sent our via email automatically.

Thanks for your feedback,

Share this post

Link to post
Share on other sites

Pretty sure you can add a hook somewhere, catch the errors you want and send out an email.

This would make great module though. Perhaps with the option to get a weekly digest of the log action. That'd be nice.

Share this post

Link to post
Share on other sites
38 minutes ago, heldercervantes said:

Pretty sure you can add a hook somewhere, catch the errors you want and send out an email.

This would make great module though. Perhaps with the option to get a weekly digest of the log action. That'd be nice.

How can I find such a hook? I don't have much experience with them yet.
Very nice idea regarding weekly emails! 


36 minutes ago, adrian said:

TracyDebugger's "production" mode has the option to email for various error types.

Wow nice module, didn't see this one before. I will check it out for sure. Thank you!

1 person likes this

Share this post

Link to post
Share on other sites

Hi @Dennis Spohr,

most things can be done with hooks. Hooks are class methods that have 3 preceding underscores, so you may find them in the php and module files in the wire folder. (Using a "search-in-files" function of your Editor / IDE: "function ___"). Or go to Captain-Hook.

Unfortunately or Fortunately, the part with sending emails on exceptions / errors seems to be completly different. It uses the native PHP register_shutdown_function, done in WireShutdown.php and therefore is not hookable through the PW system.

But the PHP docs say that it is possible to register more than one shutdown-function, and that all functions get called on shutdown. So you can register your own one. If you want to have the ability to optionally bypass processwires shutdown function, you must register yours before PWs one. (I don't know how, but would try it in site/config.php first). Than, in cases where you don't want PWs function get called, you can exit yours with exit();. Otherwise other registered functions get called and executed too.

Have a read in the WireShutdown::shutdown() function. There you see how to check if there were an error, how to get it and how to inspect it, etc.


Also there is the site/finished.php file, that gets executed at the end. But this one I haven't used til now and don't know if it get called on exceptions too.


If you test and further questions apear, come back and ask. :)

4 people like this

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By foxcraft_aw
      I have a strange problem with the "delete" method of the "pages" API-variable: When I insert a parent- and a child-page, and then immediately try to delete first the child- and then the parent-page, an exception is thrown telling me that the parent cannot be deleted, because it still contains a child-page.
      You can reproduce this behaviour using the following code:
      <?php require 'index.php'; $parentPage = new ProcessWire\Page; $parentPage->name = 'parent'; $parentPage->template = 'basic-page'; $parentPage->title = 'parent'; $parentPage->parent = $pages->get('/'); $parentPage->save(); $childPage = new ProcessWire\Page; $childPage->name = 'child'; $childPage->template = 'basic-page'; $childPage->title = 'child'; $childPage->parent = $pages->get('/parent'); $childPage->save(); $pages->delete($pages->get('/parent/child')); $pages->delete($pages->get('/parent')); (I put this code into a file called "experiments.php" in the root directory of the site, because I do not know of any better way for quickly testing out code in ProcessWire yet)
      Can you tell me why this code throws an exception?
      What am I missing?
      I am using ProcessWire 3.
      Thanks for your help!
      PS: Yes, I know about the second parameter in the "$pages->delete" method, but it should not be necessary to be set in this scenario if I`m correct.
    • By modifiedcontent
      I am trying to install Processwire + an exported custom profile and keep getting this error:
      Does anyone recognize this? What could cause this?
      I have installed Processwire + exported profiles many times before, never had problems. I have reuploaded fresh downloads for this, both regular master and dev, but keep getting the same thing.
      I am probably doing something dumb. Probably not a structural PW issue. I am out of ideas, so any feedback appreciated.
      Finally got something to install using the standard blank profile, instead of an exported profile. I am now manually reconstructing my custom site, using the new import/export functions - hit or miss so far. Did those break the ProcessProfileExport module?
    • By benbyf
      HELLO! I'm sending out quite a few (maybe 500 a day) emails from a site using WireMail. I get quite a few bounces and I'm not really sure how to handle this as i'm starting to worry abou my emailing reputation. Any thoughts?
    • By abdus
      While coding some templates I need to throw some Wire404Exceptions, which, expectedly, sets correct headers and renders 404 page. Since all these exceptions are extending Exception class, I can call its constructor with a message like this
      <?php $demoName = sanitizer()->pageName(input()->urlSegment1); $demo = pages('template=demo, name=$sanitizedPagenameFrom'); if(!$demo->id) { throw new Wire404Exception("Demo named $demoName cannot be found, but check out its source page instead"); } // inside template 404.php // somehow get the error $message echo "<h1>Page does not exist</h1>" echo "<p>$message</p>" What I want to do is to somehow catch this exception, or get inside 404 template the message that I set earlier in some module or another function, so that I can notify the user with a better message than "Error 404: Page not found".
      There's some parts inside core that handles this sort of things but they're not utilized. 
      <?php // inside /wire/core/ProcessPageView.php public function ___execute($internal = true) { // ... try { // try to render the page } catch(Wire404Exception $e) { return $this->pageNotFound($page, $this->requestURL, false, '404 thrown during render'); } // ... } protected function ___pageNotFound($page, $url, $triggerReady = false, $reason = '') { // reason is not used, or passed to 404 template } So, is there a way to manually catch the exception thrown? For instance, with Silex all exceptions can be intercepted using
      <?php $app = new Silex\Application(); $app->error(function (\Exception $e, $code) { exit('asd'); });  
    • By modifiedcontent
      Is there a built-in way in PW to do email confirmation/validation?
      Someone signs up or does something with an email address; the system sends an email with a confirmation link to make sure the user actually owns the address.
      pwFoo and justb3a both use a double opt-in (?) confirmation link in their modules, but I think they use different methods? I can't figure out how they do it. Is there a recommended way? A quick, easy way?
      I am looking into how to put this together. I would need tables in the database for a validation code, generated at signup, and a true/false for account activation. Those would be two fields in the signup template/page, correct?
      But they would have to be added to the "user template"? Confused... I thnk this post explains it.
      Ryan in that thread also points to a built-in PW way to generate a validation code.