Mishkat al-Masabih 1
‘Umar b. al-Khattab, for whom God’s good pleasure is prayed, reported God’s Messenger, to whom may God’s blessings and safe-keeping be granted, as saying:
“Deeds are to be judged only by intentions, and a man will have only what he intended. When one’s emigration is to God and His Messenger, his emigration is to God and His Messenger; but when his emigration is to a worldly end at which he aims, or to a woman whom he marries, his emigration is to that to which he emigrated.” 

(Bukhari and Muslim.)
عَنْ عُمَرَ بْنِ الْخَطَّابِ رَضِيَ اللَّهُ عَنْهُ قَالَ: قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «إِنَّمَا الْأَعْمَال بِالنِّيَّاتِ وَإِنَّمَا لكل امْرِئ مَا نَوَى فَمَنْ كَانَتْ هِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ فَهِجْرَتُهُ إِلَى اللَّهِ وَرَسُولِهِ وَمَنْ كَانَتْ هِجْرَتُهُ إِلَى دُنْيَا يُصِيبُهَا أَوِ امْرَأَةٍ يَتَزَوَّجُهَا فَهجرَته إِلَى مَا هَاجر إِلَيْهِ»