fixed the sendEmail function