If you want take the train operated by KTM to Melaka, you will have to travel to the nearest railway station at Tampin (also known as Pulau Sebang) located around 38 kilometres away from Melaka town centre.
From Tampin station you can either take a taxi or a cheap local bus (if you don't mind a bit of a walk in to town for the bus station).
If you want to take the train to Melaka, there a various KTMB train types that serve the station at Tampin.
You can travel to Tampin on the new high-speed Electric Train Services (ETS) from as far as Padang Besar on the Thailand / Malaysia border.
There are now a number of trains that stop at Tampin on their journey to Gemas (where the ETS services currently terminate).
You can use these trains to travel from popular destinations such as Langkawi (from Arau / Alor Setar), Butterworth Penang, Ipoh and Kuala Lumpur, as well as many other destinations in between.
From Singapore you will firstly have to take the 5 minute Shuttle Train to JB Sentral Station in Johor Bahru.
From JB Sentral there are a number of Shuttle Trains that travel to Gemas and from the 3rd of June 2018, all of these trains have had their route extended and now travel from JB to Tampin (now changed again to terminate at Gemas).
If you decide to take the Shuttle to Gemas, you can also connect to an ETS Train for the last part of the journey to Tampin.
If you are in Kuala Lumpur, you can take a frequent commuter service to Tampin Station on the Batu Caves - KL Sentral - Seremban - Tampin Komuter Line.
As Tampin railway station is some distance from Melaka town you really should buy your ETS and Shuttle train tickets before travelling out to the train station, as trains can often be full.
The easiest way to do this is to book your tickets online.
You can also book your Melaka train tickets from any KTM ticket counter at any mainline railway station, usually up to 60 days in advance, but advance ticket sale dates may vary.
If you want to travel on the Komuter Train from Tampin to KL Sentral, you just turn up at the station and buy your tickets for the next departure (no advance booking is available or necessary).