added email sending functionality, flash messages