Photon heating of envelopes around young stellar objects: an explanation for CO J=6-5 emission