As of August 2014, entomologists are not exactly sure why moths are attracted to flames or artificial lights, but three prevailing theories include how moths navigate, how moths breed and how bright the moon is at night. One theory is that moths are distracted by lights that are not moonlight, and another is that some portions of infrared light are the same types of energy given off by female moths.
The nighttime navigation issue revolves around transverse navigation, or the idea that animals use the sun and moon to get a sense of direction. Transverse orientation or navigation occurs when animals fly while maintaining a constant angle towards a major light source. Flames and artificial lights may disrupt that process.
The infrared part of a candle flame gives off the same light frequency as those of a female moth ready to mate, which may explain why male moths dive into flames and killing themselves. This theory has been around since 1977, when Philip Callahan published a paper in the journal Applied Optics.
Another theory is that moths going into flames depends upon how bright the moon is during the night. Moths do not seem to be as attracted to ultraviolet lamps during the full moon, supposedly because the moon is at its brightest.