Islam has specified some conditions for fasting (Swam) to be accepted.
" Oh Allah, we fast for you, and break our fast with your blessings, so accept [our fasting]. Indeed, you are the All-Hearing, the All-Knowing."
From Imam Ali's (AS) supplication before Iftar.