Water-borne sewage has been known for a long time: 2500 BC water collection system existed in Mesopotamia. Later systems were found in Knossos, Crete. Romans maintained quite sophisticated systems: the Coliseum had 1 toilet for every 25 seats!
After the fall of the Roman Empire the technology got forgotten. Between 1346 and 1453 one third of the population died in Europe due to diseases, most waterborne (typhoid fever, cholera).
1388 a law in England prohibited dumping of night soils and garbage into ditches; they had to be carried away.
Water closets were introduced in England in about 1810 and became quite popular by 1850. They usually discharged into pits, but most often these were opened to street gutters and streams. One epidemic of cholera in London claimed 50.000 lives. 1859 the Thames in London was a “lone vast cloacae” with a “stench so foul, we may well believe, had never before ascended to pollute this lower air”.
As from 1865, raw sewage was irrigated onto land, on which grass, potatoes, cabbage etc. was grown.
From about 1900 mechanical treatment (screens and later primary settling tanks) was introduced. But cities got too big. There was not enough land for irrigation. So they went back to releasing mechanically pre-treated sewage into rivers.
Around 1960 biological treatment to reduce organic load (C) was developed. Standards for sewage treatment plants appeared. With ever growing cities, eutrophication became a problem, and from the late 1970s onwards, a lot of effort was put into eliminating nitrogen and phosphate as well.
Today a stringent set of standards for effluent discharged into the environment or being re-used (irrigation) is in place in all civilized countries. Technologies have been developed to adhere to these, even in small plants.