The usual cause is a bad USB cable. I had 2 HTC M8's, though, and both had the USB port itself go bad. So I would consider that possibility as well on yours. It's also an old phone now and it could be that the battery is toast and not able to charge.
If a new cable doesn't fix this, then I'd suggest looking at replacing the phone. Given its age, it's not likely worth paying to have it repaired.