Alqamah bin Waqqas al-Laythi said: I heard Sayyiduna Umar bin al-Khattab (may Allah be pleased with him) saying: I heard the Messenger of Allah (peace and blessings be upon him) say: "Deeds depend entirely upon intentions, and a person shall have only what he intended. He whose emigration was to Allah and His Messenger (peace and blessings be upon him), his emigration is to Allah and His Messenger; and he whose emigration was to attain something of this world or to marry a woman, his emigration is for that to which he emigrated."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الخلع والطلاق / 14996