HTC One M8 will not charge

Welcome to Android Central! Perhaps the port is damaged, like you are thinking. How old is the phone?
 
The charging port only works when plugged in at certain angles
That's the definitive problem that diagnoses an unsoldered pin on the charging port. You either rework it (unsolder the port, clean the board, resolder the port), replace it with a new one or replace the board it's on - all this assuming that you've worked inside cellphones before.

If you haven't, bring it to a repair shop for a replacement. (The port is about a buck, the board is about $5, so it doesn't matter which one they do - the labor is many times more expensive than the part.)