Sayyiduna Umar bin al-Khattab (may Allah be pleased with him) said: I heard the Messenger of Allah (peace and blessings be upon him) say: "O people! Actions are only by intentions, and a person shall have only what he intended. So whoever emigrated to Allah and His Messenger, his emigration is to Allah and His Messenger; and whoever emigrated for some worldly gain he would attain, or for a woman he would marry, his emigration is to that for which he emigrated."
(b) In the hadith of Sulayman bin Harb, the words "O people" are not present.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الطهارة / 1031