This morning I fixed my sixth or seventh iPhone with this apparently common problem. Over time, the Lightning charging port at the bottom of the phone can fill up with lint or other debris, especially for people who carry their iPhones in their pocket. The gunk gets increasingly compacted every time the charging cable is plugged in, until it accumulates to the point where the phone charges intermittently or not at all because the charging pins are no longer making good contact.
You should be able to insert the charging cable all the way into the port. If you can’t, it is very easy to correct the problem. First, switch off your phone to avoid any possibility of creating a short circuit. Using a toothpick or other suitable tool (a tiny flat head screwdriver like you’d find in a precision screwdriver set works perfectly), clean out any junk in the port. Try plugging in a charging cable and repeat if it still isn’t seating correctly.