From 60 days in advance you can book your train ticket for a train trip in Thailand. Great! And when traveling by night-train (sleeper) that might be a good idea to do. When you are on holiday and want to travel on a planned day it would be a problem to find the train fully booked. So just go to the web-site of the State Railway of Thailand (SRT) and book your ticket online! You can book by telephone (call 1690 within Thailand) but you will have to pickup your ticket at a major train-station within 24 hours after making the telephone call. Well then you could as well just go to the train-station directly, right? That is what I always did as I was living near a major train-station in Thailand. But well, suppose you are not in Thailand and want to be sure that you will have a train-ticket. What to do?
Well actually since 2017 you can book online via State Railway of Thailand (SRT) (but in the beginning it did not always work). Just go to Thai Railway E-ticket, pay with credit-card and your ticket will be send as PDF by email.
There are also a few other ways of booking online, from the time that the SRT did not have online booking. But of course you a little bit extra for this services :