“What then,” it may be said, “ought we not to pray in church?” Indeed we ought by all means, but in such a spirit as this. Because everywhere God seeks the intention of all that is done. Since even if you should enter into your closet, and having shut the door, should do it for display, the doors will do you no good.
It is worth observing in this case also, how exact the definition, which He made when He said, “That they may appear unto men.” So that even if you shut the doors, this He desires you duly to perform, rather than the shutting of the doors, even to shut the doors of the mind. For as in everything it is good to be freed from vainglory, so most especially in prayer. For if even without this, we wander and are distracted, when shall we attend unto the things which we are saying, should we enter in having this disease also? And if we who pray and beseech attend not, how do we expect God to attend?
Source: Homilies on the Gospel of St. Matthew (New Advent)