refactoring function send_email_with_error_log