The emission of madhiy (prostatic fluid) does not invalidate the fast, whether it happens because a man is thinking or kissing his wife or for some other reason. This is the view of Imam al-Shaafa’i (may Allaah have mercy on him). See al-Majmoo’ by al-Nawawi, 6/323
Shaykh al-Islam Ibn Taymiyah (may Allaah have mercy on him) said in al-Ikhtiyaaraat, p. 193:
The fast is not broken because of madhiy that is emitted because of kissing, touching or repeated looking. This is the view of Abu Haneefah and al-Shaafa’i, and of some of our companions.
This is also the view of Shaykh Ibn ‘Uthaymeen (may Allaah have mercy on him), as was stated in al-Sharh al-Mumti’, 6/390, where he said:
The proof concerning that is that there is no evidence to say that the fast is invalidated thereby, because fasting is an act of worship that is enjoined on man, and this act of worship cannot be invalidated unless there is evidence that something invalidates it.