Magma needs to be hot in order to be molten. If it were cooler it would be rock! It gets its heat from deep in the Earth from the decay of radioactive material in Earth mostly.