I had similar issues with my iPhone SE for months where the charging kept staying on and off whilst charging. I had to hold the cable in for it stay charging. Very frustrated !!!.
I then realised that there was something maybe at the base of the charging port preventing my charging cable to be fully inserted. I powered off the phone completely. I then used the sim card removal pin (It’s metal of course) and placed it right down to the bottom of the charging port. I gently scraped the bottom left to right and right to left 5 times. I pulled the pin out and sure enough some rubbish fallen out. I repeated this process two more times until there was no rubbish fallen out of the port. I then powered up the phone and tested my charging cable. It charges immediately without me having to hold the cable in. The charging cable is working for the last two weeks now without any issues whatsoever. I may have to do this whenever, i have issues with intermittent charging problem.
CAUTION NOTE: Do not insert anything in the charging port without POWER OFF your phone completely.