I am a happily married man. But for a reason I don't know, this past week my mind has been driving me nuts with thoughts of other women, etc. These thoughts are so powerful. Is there a way to stop them? Are there any extra prayers I can be reciting? Is there so extra type of learning I can take on?
The most powerful tool in all these matters is perhaps the most counter-intuitive. It's called "hesech ha-daat." AKA: think about something else.
I know it sounds stupid, but this is how it works: When you fight against your own thoughts, you only engrave them deeper in your neurons. It's something like struggling against quicksand, which serves only to dig you in deeper and deeper.
So as long as you are chastising yourself for your thoughts, trying to determine where they come from, trying to convince yourself more and more how bad they are for you and even just remarking to yourself "why is this happening now?"--all you are doing is burning those thoughts further into the woodwork of your mind.
You need to do two things:
1. Recognize that you and I and 99.9999% of the male gender are beasts of prey with oversized brains. It's no wonder we react to a woman much the same as we do to a steak. That's how we were designed. The brain software is supposed to kick in and modify that, but sometimes the hardware just gets whacko out of control. So there's nothing to be shocked about--or to chastise yourself about when those hormones start flowing and those thoughts start bubbling.
On the contrary, you should be delighted that you had an opportunity to do battle with your yetzer hara (your animal desires) and you won, because you still have not committed adultery or any similar such sin. For more on this, you need to see chapter 27 of Tanya. We have that text online, or click here for an audio class on the subject (but learning it inside from the text will help you even more).
2. You need to have something else ready in your mind to think about. If you're not learning, you're sinking. Always have some ideas in Torah ready at hand to think about. Memorize as much as you can. Listen to tapes. Learn stuff that engages and fascinates you. An empty mind is an open door to empty thoughts. Keep that brain stuffed with good thoughts.
Rabbi Tzvi Freeman for Chabad.org