moved mailer function so database connection must be made