Hello,
Interesting history. This is a psychosomatic problem that you are experiencing. Unconsciously you are having a guilt feeling & that's causing your libido to fall & ED when you are with your wife.
Its quite natural for a marriage to die when an affair happens, no big deal. Life goes on & marriage continues though boring, not all marriages result in divorce. You can read some books on affairs with your wife to reduce your guilt, shame or stigma that unconsciously disturbs you. This may help elevate your libido.
For ED, you can take medicines like
Sildenafil (Viagra)
Tadalafil (Adcirca, Cialis). It is effective. However, ED is also caused due to stress,
depression,
anxiety & relationship tension. You may need the help of a
Psychiatrist or counselor if the problem prevails for long. By the way, always use safe sex & avoid multiple partners to stay protected from STD(sexually transmitted diseases). Cut on smoking or addictions if any.
Hope I have answered your query. Let me know if I can assist you further.
Regards,
Dr. Nupur K, General & Family Physician