Forrest Mars, Sr., the founder of the Mars Company, got the idea for the confection in the 1930s during the Spanish Civil War when he saw soldiers eating chocolate pellets with a hard shell of tempered chocolate surrounding the inside, preventing the candies from melting.
Mars received a patent for his own process on March 3, 1941. One M was for Forrest E. Mars Sr., and one for Bruce Murrie, the son of Hershey's Chocolate president William F. R. Murrie. Murrie had 20 percent interest in the product. The arrangement allowed the candies to be made with Hershey chocolate which had control of the rationed chocolate. During the war, the candies were exclusively sold to the military. Mars bought out Murrie after the war, but kept the name. Murrie was also the guy who came up with the Mr. Goodbar (chocolate with peanuts) idea.
You can special order M&Ms with a saying or name on them from its web site. I did this for a birthday present. It is a bit pricey, but much fun, especially for children to see their own name on the little goodies.