Hi,
First, how long have you had the laptop? If it is less than 12 months or just a bit more, then I suggest that you verify the purchase date and if it is still within the 'warranty' period then consult the documentation that came with the laptop as to what you have to do to make a claim for a manufacturer's warranty repair or replacement.
If it is no longer under warranty read on.
When you plug in the headphones, do the laptop speakers cut out, like they are supposed to?
If so then the most likely problem as you already know is that the headphone socket is most probably faulty.
The right headphone connects through the 'ring' connector of the jack and socket. Either the spring in the socket which connects to the 'ring' connection of the jack when it is inserted has lost tension and is not connecting properly or the socket has a dry solder joint on the systemboard for that particular connection.
Unfortunately for you the socket is mounted directly on the systemboard. To repair it you would have to remove the system board from the laptop and use soldering tools and skills to remove (or remount) the faulty headphone socket and replace it with a compatible replacement part.
Here is a link to the service manual for your laptop. On p.58 it details the prerequisite actions and procedures necessary to remove the systemboard from the laptop case. Again unfortunately for you it does not give an individual part number for the headphone socket, only for the systemboard itself. There are different wiring configurations for headphone sockets even though they look the same from the outside, so you need the correct one. Replacing the systemboard to fix the headphone socket problem is a bit of overkill.
If this seems a bit daunting and you wish to have it working properly, then I suggest that you contact a reputable, professional laptop repair service in your area and ask for a quote to repair your laptop.
http://www.hp.com/ctg/Manual/c02131229.p...
Hopefully this is of some help.