control mail function by using if statement

control mail function by using if statement