Are you using an adapter to go down from the large 6.3 to 3.5mm headphone jack?
If so, try a different adapter. You can get gold plated ones from China for $1 off ebay usually including post. Otherwise it sounds like the socket in the back of the keyboard is faulty. If wiggling the headphone plug in the back intermittently fixes it then this is typically the problem.
You can sometimes bend the contacts in the socket its self to improve things. This usually means taking the lid off.
If you are not a technical type, and it is not under warranty, then I would consider using a laptop, usb-MIDI cable, and some piano package.