Shaitan tries to divert the attention of people from the prayer to other things, that it is why, it is recommended to say after Takbiratul Ehraam when you start the prayer (A'ootho Billah Minashshaytan Arrajeem)أعوذ بالله من الشيطان الرجيم
Your prayer is still valid even if you think outside the prayer, but the reward will be decreased as the Hadeeth says: The prayer will be raised to the sky as much as the attention is in the prayer. لا يرفع للعبد من صلاته إلا ما وعى
It is very important to know while you are praying that:
You are in front of Allah and you are talking to him.
We need to remember our sins and be very humble in front of Allah, seeking forgiveness.
Also we need to remember our definite end in this life and our next life in our grave then our final place in the hereafter where it will be either Paradise or Hellfire God forbid. Remembering these facts will make our prayer more dedicated and our mind more concentrated on the Prayer.