When an electron absorbs energy either from light (photons) or heat (phonons), it receives that incident quantum of energy. But transitions are only allowed between discrete energy levels such as the two shown above. This leads to emission lines and absorption lines.