All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
Emission of semen and Madhiy from a man or a woman due to only thinking does not break the fast according to the Hanafis, Shafi’is and Hanbalis. Their opinion is based on what was stated in Al-Bukhari and Muslim (the wording is for Al-Bukhari) on the authority of Abu Hurayrah who said (attributing it to the Prophet ): “Allah has forgiven my Ummah for what is whispered to them or what enters their minds, so long as they do not act upon it or speak of it.” And our Fatwas are delivered in conformity with this. Dear brother, we advise you to do your best to preserve your fasting from what disgraces it or diminishes its reward, keep yourself busy with acts of worship and permissible things, and do not leave it as a prey to the whispers of Satan.
Allah knows best.