First, you need accountability. Both in person and software. Covenant Eyes keeps a log of websites you visit and reports them to the person you choose. There are others available as well. Find a man in your church you feel comfortable being open with. If your phone is an issue, keep it somewhere else at night.
Second, I seriously recommend biblical counseling. Whether from your pastor or a trained/certified counselor. And biblical
counseling, not just "Christian counseling". Look here. https://biblicalcounseling.com/counselors/
Third, keep a journal. Write down when you fall. What happened before? What time? Is there something in common with the times you fail? How do you feel afterwards? Are you loving your wife as Christ loved the church? Remember how you feel afterwards and think about that when you are tempted.
But also track your victories. Is there something you do regularly when you overcome temptation?
Memorize scripture. Quote it when you are tempted. Pray when you are tempted. Call your accountability partner when you are tempted. Pray with your wife when you are tempted.