Can he pray two rak‘ahs with more than one niyyah (intention)?
Praise be to Allah
Combining of acts of worship falls into two categories:
The first category:
The first category includes acts of worship where it is valid to combine those acts. The guideline concerning that is that one of the two acts of worship is not intended for its own sake. In this case it is permissible to combine them, so that one deed counts as two.
An example of that is the two rak‘ahs to “greet the mosque” (tahiyyat al-masjid) and the two rak‘ahs following wudoo’, and similar prayers that are not intended for their own sake. So it is permissible for a person to pray two rak‘ahs with the intention of offering the two rak‘ahs following wudoo’ and the Sunnah prayer of Maghrib, as the questioner mentioned, because the purpose of the two rak‘ahs following wudoo’ is so that the Muslim prays straight after making wudoo’, whether it is his regular prayer or Duha prayer or some other prayer.
Another example of that is “greeting the mosque” (tahiyyat al-masjid), because the purpose of this prayer is that the one who has entered the mosque does not sit down until he has prayed.
Shaykh Khaalid al-Mushayqih said: “Greeting the mosque” is not a prayer that is intended for its own sake, so it may be combined with another prayer, such as the regular Sunnah prayer. So if you enter the mosque to pray Zuhr, then you can pray two rak‘ahs with the intention of the regular Sunnah prayer and with the intention of greeting the mosque. If you intend to greet the mosque and to offer the regular Sunnah prayer, you will attain the reward of two prayers in two rak‘ahs. If you do wudoo’ and come to the mosque with the intention of offering the regular Sunnah prayer and greeting the mosque and praying the two rak‘ahs following wudoo’, then you will attain the reward of three prayers in two rak‘ahs. This is one of the benefits of forming the intention. Similarly, if a person does wudoo’ for Duha, then prays two rak‘ahs, intending them to be the two rak‘ahs following wudoo’ and the two rak‘ahs of Duha, he will attain the reward of two prayers in two rak‘ahs.
End quote from al-‘Aqd ath-Thameen (p. 161).
The second category:
The second category includes cases where combining acts of worship is not allowed. That is if each of the two acts of worship is intended for its own sake. In this case it is not possible to combine two intentions for one action.
Shaykh Ibn ‘Uthaymeen gave an example of that. He said: A man missed the Sunnah prayer of Fajr, until the sun rose and the time for Duha prayer came. In this case, the Sunnah of Fajr cannot suffice for Duha prayer, and Duha cannot suffice for the Sunnah of Fajr, and they cannot be combined either, because the Sunnah of Fajr is separate and the Sunnah of Duha is separate. Doing one of them does not suffice for the other.
Similarly, if one of them is connected to the one that came before it, then they cannot be combined. If someone were to say: I want to form the intention to combine the obligatory prayer of Fajr and the regular Sunnah of Fajr, we say: That is not valid, because the regular Sunnah prayer is connected to the (obligatory) prayer, so doing one of them does not suffice for the other.
And he said: A similar example is the Sunnah prayer following tawaf and the Sunnah prayer of Fajr. For example, if a person finishes his tawaf after the adhaan for Fajr prayer and before the iqaamah, and he intends to combine the Sunnah prayer of tawaf with the Sunnah prayer of Fajr, this is not valid, because doing one of them does not suffice for the other, because the Sunnah of tawaf is to be intended for its own sake, and the Sunnah of Fajr is to be intended for its own sake.
End quote from Liqaa’aat al-Baab al-Maftooh.
As-Suyooti said, quoting an-Nawawi: … If one of the two sunnahs is not implied by the other, then the intentions thereof should not be combined in one act, such as the Sunnah prayer of Duha and making up the Sunnah of Fajr. This is unlike greeting the mosque and the Sunnah of Zuhr, for example, because greeting the mosque may be implied and included in the Sunnah of Zuhr.
End quote from al-Ashbaah wa’n-Nazaa’ir (p. 23).
See also: al-Majmoo‘ Sharh al-Muhadhdhab (5/75)
One of those who explained this principle in great detail was al-‘Allaamah ibn Rajab (may Allah have mercy on him) in his book al-Qawaa‘id (p. 23)
And Allah knows best.