How to get my music from my iPhone to my Mac?

My computer crashed, and I had to replace the hard drive. I have around 1000 songs on my iPhone, not all of which were downloaded from iTunes. How can I get these songs back on my Mac laptop without having to pay?

You are able to can allow automatic downloads of purchased media in iTunes and run a Time Machine backup of all personal data. IPods and iOS devices are not backup or storage devices.

For music not from iTunes store, you need a 3rd party software to copy the music from your iPhone to Mac. You may take a look at this website, it collects 5 free iPod to Mac transfers without limitation, I'm sure you will find one you need.