It was narrated that 'Umar bin Al-Khattab, may Allah be pleased with him, said that the Messenger of Allah said:
Actions are but by intentions, and each man will have but that which he intended. Whoever emigrated for the sake of Allah and His Messenger, his emigration was for the sake of Allah and His Messenger, and whoever emigrated for the sake of some worldly gain or to marry some woman, his emigration was for that for which he emigrated.