working version of an email function