You can't afford not to sort this out, if you don't have the money for an initial block of therapy sessions, then you need to get digging yourself.
I'd suggest you start journalling, that can be really helpful to give you some perspective and reflection on what you're doing and why, and see patterns, however given the nature of what you're trying to deal with it's probably not a good idea to have the details discoverable.
If you want it to stop you need to stop it, you need to go cold turkey, delete the numbers, go scorched earth, tell him you never want to hear from him again and it is over without question, you value your family too much, he means nothing to you, then back yourself up by meaning it.
Now the shine has worn off you're left with a nasty habit much like a drug that you know isn't serving you in general, but it is paying you in some way, you need to work out what that is to stop it reocurring. If it's low self esteem you've got yourself into a vicious circle, because the affair is sending your self esteem lower and lower, and so it goes.