removing the email submitting portion from submitevent and putting it into a functin