Starting from 1st February 2017, you will be able to buy train tickets online from the State Railway of Thailand. You can use credit cards (Visa, MasterCard, JCB) or debit cards to buy the e-tickets at either www.railway.co.th or www.thairailwayticket.com (latter not online yet). You can purchase tickets up 60 days in advance and no less than two hours before the train is scheduled to leave. Only four tickets are available per booking. The booking fee is 40 Baht per 1st Class ticket, 30 Baht for 2nd Class tickets, and 20 Baht for 3rd Class tickets. At the moment, you cannot use the website to buy discounted discounts (for example for children), to reserve free tickets (Thai nationals only), and for special excursion trains (for example to the sunflower fields or to the beach). Once you have purchased the tickets, you need to print them out. You cannot show them on your smartphone. It is possible to cancel tickets online or at your local train station.
Source: Public Relations Department of the State Railway of Thailand