Umar bin Al-Khattab (radi Allahu anhu) reported: The Messenger of Allah (sal Allahu alaihi wa sallam) said, “The deeds are considered by the intentions, and a person will get the reward according to his intention. So whoever emigrated for Allah and His Messenger, his emigration will be for Allah and His Messenger; and whoever emigrated for worldy benefits or for a woman to marry, his emigration would be for what he emigrated for.”
[Al-Bukhari and Muslim]
According to some Ahadith, the reason for this Hadith is that a person sent a proposal of marriage to a woman named Umm Qais, which she turned down saying that he should have to emigrate to Al-Madinah for it. Accordingly, he did it for this specific purpose, and the two were married there. On account of this event, the man came to be known among the Companions as Muhajir Umm Qais.
On the basis of this Hadith, the ‘Ulama’ are of the unanimous opinion that the real basis of one’s actions is Niyyah (intention) and everyone will be rewarded according to his Niyyah. It is true that Niyyah is established in one’s heart, that is to say, one has to first make up one’s mind for what he intends to do and the Niyyah should not be expressed verbally (In fact, expressing the Niyyah verbally is a Bid’ah (innovation in religion) because no proof of it is found in Shariah).
The point which becomes evident from this Hadith is that Ikhlas (sincerity) is a must for every action. In other words, in every righteous deed, one should seek only the Pleasure of Allah; otherwise, it will not be accepted by Allah.
And Allah Knows Best!