Added uninstall hook, separated part of the email body to a function, added debug_log calls in case of mail error.