It is narrated from Sayyiduna Abu Usayd al-Sa'idi (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: "When one of you enters the mosque, let him send the greeting of peace upon the Prophet (peace and blessings be upon him), then say: 'Allahumma iftah li abwaba rahmatik' (O Allah, open for me the doors of Your mercy). And when he leaves, let him say: 'Allahumma inni as'aluka min fadlik' (O Allah, I ask You of Your bounty)."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 4319