sub function for sending email