Prayer is intended to elevate and strengthen people. Therefore, knowing that one is about to be uplifted and brought closer to Hashem, a person must approach prayer out of joy and not while in a state of sadness or apathy.
The Chachamim teach (Berachot 31a; Shulchan Aruch 93:2), “One should not pray out of laughter,” because laughter nullifies one’s awe for God, and a person must pray out of fear and submission. “Nor amidst talk,” because chatter distracts a person from his inner world and prayer is supposed to emerge from the depths of one’s soul. “Nor from lightheadedness and idle words,” because prayer is based on the recognition of one’s ability to do wonders with his speech, and if a person comes to prayer with idle words, he demonstrates that he does not value his speech (see Olat Ra’ayah, part 1, p. 29).
It is good to give tzedakah before praying (Shulchan Aruch 92:10), for by doing so one approaches prayer pleased and uplifted from the mitzvah he just performed. Furthermore, when we come to pray and request kindness and compassion from Hashem, it is proper that first we ourselves show mercy on the poor. The Ari HaKadosh says that before prayer it is good to reflect upon the mitzvah, “V’ahavta l’re’acha kamocha” (“Love your fellow Jew like yourself,”) for this is a great Torah principle. The prayers are written in the plural because we are praying for the nation as a whole.
One should not begin to pray when his mind is preoccupied. Even someone who has the privilege to learn Torah before praying should try not to come to prayer immediately after learning a very complex subject of study. His mind is liable to be absorbed in thoughts of the topic that he has been studying, and he will not be able to concentrate properly on his prayer. Instead, before praying, he should learn straightforward matters of halachah, or uplifting essays on emunah (faith). B’dieved, one should not avoid praying in a minyan, even if he is preoccupied with matters of Torah or has other concerns (Shulchan Aruch 93:3; Mishnah Berurah 6).
The Chachamim instituted the recital of uplifting verses prior to praying the Amidah, so that before the Amidah people would be engrossed in inspiring and elating matters. Before Shacharit and Ma’ariv, we recite the berachah, “Ga’al Yisrael,” and before Minchah we say Ashrei (Shulchan Aruch 93:2).
The Talmud records that devout people paused to meditate a full hour before praying so that they could properly direct their hearts to their Father in Heaven (Berachot 30b; Shulchan Aruch 93:1; Mishnah Berurah 1).