Chosen Solution

After replacing the battery my phone turns off by itself while using it. I thought that the battery might’ve been defective so I tried a different battery. Still no luck.

Was the original battery doing the same thing or did it have a different problem? If it is doing the same thing, then you’re problem may be with the charge circuit. This involves the charger, the Lightning Cable, the Lightning Port and the charge circuit on the logic board. You have to use known-good parts and eliminate them one by one. When everything else is eliminated and only the logic boar dis left, that’s when you find a micro-soldering repair shop. If the original battery had a different problem, then it may just be a bad replacement battery. There are a lot of junk batteries on the market so depending on where you got it, it may be the issue. As I mentioned above, ideally, you need to have a known-good battery as a reference point.