Fixed bug in mail function