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.
Initially the Muslim should stay away from studying or teaching in mixed schools as this would lead to disastrous consequences, among which is what you mentioned. In fact, when males and females meet often, there is a high probability that they engage in illicit relations or even illicit acts. So, if the person finds himself compelled to study in such environments, he should lower his gaze and control his sexual desires. He should avoid sitting with members of the opposite sex or staying with them in seclusion. The solution in the case you mentioned is as you suggested: "marriage". The Prophet said: “The best solution for those who love each other is to marry.” [Ibn Maajah]
What is meant by marriage is the marriage that fulfills all the conditions of a valid marriage.
For more benefit in this regard, please refer to Fatwa 83629.
As for the marriage that lacks all these conditions or any of them, it is not permissible in Islam and no person should undertake it (lack of Wali, witnesses, temporary marriage, etc.). You and these students should stop immediately such relations between males and females, and you should repent from this and have deep regret for having indulged in it in the first place.
Allah knows best.