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