It's usually a dodgy earth on the tailgate hinges
Make sure you do the following
1) clean up the contact pins and plates - use brasso or something

2) tap back the pins securing the tailgate door to the main body of the car. Stick a thin layer of castrol grease on em or similar and then tap them back
That should solve any electrical problems you are having with the tailgate. Especially the grease on the hinges, solved my tailgate remote release not working properly