How to display a hour glass during some processing is going on?

I am trying to display please wait or some animated gif to indicate to the user that there is a process going on. Especially during email send takes long time to process. However these are shown only after the email has been sent. Basically it does not output the echo even though the echo is very much kept in the beginning before the processing starts. Any thoughts?