The heat comes from nuclear fussion. The futher into a star you are the greater the pressure is due to gravity and so the atoms are squished together more and the amount of fussion happening goes up and more heat is released.
In these regions the processes that lead to heating (energy gain) and cooling (energy loss) are very different, leading to different temperatures and densities.
The main heating mechanisms of the corona are though to be the following four: dissipation of energy from ion oscillations in the solar magnetic field – so-called Alfven waves, dissipation of energy of the magnetic fields themselves, thermal conduction and the flow of mass from the sun’s surface. Which of these is the most important is still being debated, but the consensus is growing towards Alfven waves.
This is a puzzling one, since the second law of thermodynamics says that heat can’t flow from an area of low temperature to an area of high temperature. But that’s doesn’t mean that heat can’t be pumped from an area of low temperature to an area of high temperature, other wise your fridge wouldn’t work: it pumps heat from a cold area (inside the fridge) to a hot area (the room). But if heat is being pumped around, then there must be something doing the pumping. In the sun there must be something that is pumping heat from the surface to the corona. Whatever this thing is it must come from within the sun and be very energetic. My guess would be either high-energy radiation from the nuclear reactions inside the sun, or something to do with magnetic fields.
Now I’m not an astrophysicist, so that’s as much as I’ve been able to work out off the top of my head. I’ve now gone away and read some stuff about this problem and it seems that no one is really sure what is pumping all that heat, but people think that it’s probably several different mechanisms all to do with the sun’s magnetic field.
I was close with my guess! 😛