All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
The treatment of magic and safeguarding oneself agaisnt it can be done by reciting the Quran much, reciting the supplications of the mention of Allaah in the morning and evening, and the supplications of leaving and entering the house, etc…that are confirmed from the Prophet in addition to supplicating Allaah much.
However, first of all, one should always perform the obligations of Allaah and be steadfast on His Religion.
If a Muslim adheres to all of this, then no magic could affect him, and nothing will happen to him except what Allaah has predestined to happen to him.
Therefore, we advise our dear questioner to stick to the obligations, to supplicte Allaah much and recite the authentic legislated mention of Allaah that are confirmed from the Prophet . Then, if you are affected by magic or anything else that you dislike, you may make it ineffective it by reciting the Quran on it, as the whole Quran is a Cure, Mercy, Light and Guidance.
You can also recite the Quran on water and drink from it and have Ghusl (ritual bath) with what remains of it, and other methods.
Some scholars say that one should read Chapter Al Faatihah [Quran 1], verse 255 from Chapter 2, Chapters 112, 113 and 114, and the verses that make magic ineffective from Chapters 7, 10, 20 and 26.
For more benefit, please refer to Fataawa: 82488, 82918 and 81559.
Allaah Knows best.