How to make sure that form is submitted successfully and send a confirmation email?