What might cause garage door opener sensors to work intermittently?
if sunlight on the sensor isn't causing the issue, then the problem is either bad opener, bad wiring or a bad sensor.

when the sensors are not working, use a multimeter to test the voltage put out by the opener. if that's not right, then you might have a bad opener.

next i would try disconnecting all of the wires at both ends, cutting off the exposed conductor and stripping the wires fresh, then reconnecting. make sure to thoroughly clean any corroded terminals.

if neither of those are the issue, then you need to decide which is easier for you: replacing the sensors or replacing the wiring. do one of those, and if that doesn't fix it then do the other.