All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
There is no basis for what your teacher said. We have explained the conditions of a valid marriage in fatwa 83629, so please refer to it.
Marriage is one of the virtuous customs. It is permissible in principle, but it includes the meaning of worship, as stated by some scholars. However, it is not one of the pure acts of worship for which sincerity is an obligation such that if sincerity is lacking, it becomes invalid.
If someone has the intention of getting closer to Allah by getting married, then he will be rewarded for it. The Prophet said, “The intimacy [i.e. having sexual intercourse] of one of you (with his wife) is an act of charity.” They said, “O Messenger of Allah, if one of us fulfils his desire, will he be rewarded for that?” He said, “Do you not see that if he fulfilled it in a forbidden manner, he would bear a sin for it? Likewise, if he fulfilled it in a lawful manner, he would be rewarded for it.” [Muslim]
An-Nawawi said:
“This [hadeeth] is evidence that the permissible acts become acts of worship if accompanied with sincere intentions; so intercourse would become an act of worship if one, through it, intended to fulfill his wife’s right and keep good marital relations with her, which is something that is ordained by Allah; or for seeking a righteous child; or for keeping oneself chaste; or for keeping the wife chaste; and for preventing both of them [the husband and wife] from looking at what is forbidden, or thinking about it, or having the intention of doing it; or if one intended other good intentions.”
Allah knows best.