sendEmail javascript function - not tested