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.
The Prophet Muhammad guided the youth to the best solution. He advised them to marry as soon as possible and taught them how to control one's sexual desires; he said: “O young people! Whoever can marry should marry, as it helps to lower one’s gaze, and protects one’s private parts, and whoever is not able to marry should fast, as this helps him to protect his private parts (from committing illegal sexual intercourse).” [Al-Bukhari and Muslim] Also, the Prophet forbade living in non-Muslim countries as he said: “I am free from any Muslim who lives among polytheist”. [Abu Dawood and At-Tirmithi].
Based on the above Hadeeth the Muslim scholars agreed that living in non-Muslims countries and traveling there is forbidden except if there is a benefit for doing so, such as business, medical treatment or gaining a knowledge that is not found in Muslim countries and which is important for the Ummah.
You should know that living in non-Muslim countries is permitted only when a Muslim is able to perform his religious rites openly and feels safe from being tempted.
If he feels that he could be tempted and commit sins, then he is not allowed to go there under normal conditions. Sometimes a Muslim does not take into consideration the above Islamic rules and consequently ends up doing bad things; in this case, he should blame only himself.
Hence, if you live there for a sound reason and you face temptations which you are not able to avoid, then you should marry a girl from your country and spend a period of time with her and a period of time at your study, though this procedure delays completing your study. Or you could marry a religious woman in that country without intending to divorce her.
As for the marriage with the intention of divorce after finishing the study, then the Muslim scholars have different opinions. Some scholars permitted it, and Imam Ibn Qudamah wrote that this is the opinion of the majority of the Muslim scholars. They believe that the intention is a secret matter (only Allah knows it) and perhaps it may be changed after some time.
Some other scholars prohibited it believing that in this practice there is a kind of cheating the woman and this contradicts the saying of the Prophet Mohammed : “None of you is a true believer until he loves for his brother what he loves for himself ”. [Al-Bukhari and Muslim].
No doubt, a person does not want his sister or daughter to be treated this way. Beside that, there is much harm caused by this practice, such as leaving the children (if any) and exposing them to be spoilt and subjecting the wife to commit illegal sexual intercourse after separation, etc.
In addition to this, this behavior defames the Muslims.
We ask Allah to bless you, guide you to the right path and protect you from all distress.
Allah knows best.