The dirt cheap Circumvesuviana goes to the Porta Marina Entrance (train stop "Pompeii Scavi/Villa Mistiri" about half hourly. It leaves from the lower level of the Main Naples station where you get off the (Trenitalia or Frecciarossa, long distance railroad) train from Rome.
"scavi" means, roughly, the excavation, so we are using it here to distinguish between the famous tourist attraction and workaday modern Pompeii city.
You are remembering a poster who (OPINION: wrongheadedly) valued remaining on the train from Rome over practicality.
Pompeii is closer to Naples than to Sorrento, but it's a simple daytrip from either place.