Sayyiduna Umar (may Allah be pleased with him) said that the Messenger of Allah (peace and blessings be upon him) said: "Actions depend on intention, and a person shall have only what he intended. So whoever's emigration is for Allah and His Messenger (peace and blessings be upon him), his emigration is to Allah and His Messenger (peace and blessings be upon him); and whoever emigrated to attain the world, his emigration is to the world, or (whoever emigrated) for a woman in order to marry her, then his emigration is to that for which he emigrated."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصيام / 8108