Originally, "thank-you-
ma'am" referred to a
bump or a
dip in the road that
jostled the riders in a
carriage or later, a
car. The more common explanation for the name is that the roughness made
passengers
nod as if they were acknowledging a
favor, although a minority of etymologies claim that it derives from male and female passengers being thrown together during the bump and having a chance for a fleeting
touch or steal a
kiss. Other
explanations offered by readers of the
A.Word.A.Day mailing list included the jostle's resemblance to the pain of being
spanked by a female teacher, who required thanks for the
discipline, and the resemblance of the jostling to a
rabbit bouncing through mating: "
Wham, bam, thank you ma'am!" However, the
Oxford English Dictionary and every other
dictionary I can find prefers the first explanation.
The OED citations range from 1849 to 1897, but Franklin D. Roosevelt used the expression in a speech discussing pitfalls on the road to recovery from the Great Depression, and in baseball, the phrase has sometimes meant "a weak ground ball hit back to the pitcher for an easy out."
Sources:
http://dictionary.oed.com/cgi/entry/00250321
http://www.bartleby.com/61/29/T0142900.html
http://wordsmith.org/awad/awadmail74.html
http://wordsmith.org/awad/archives/0302