fixed errors and added email functionality

fixed errors and added email functionality