corrected email sending logic