Yes, you can. 2 solutions:
1) queue up in train station for the next train (it will take time but you can buy your ticket in the last minutes)
2) buy your ticket from the machines in the station. Choose your destination by typing the name for arrival sation (Marseilles for example), and follow the instruction, (2nd class or 1st class, single or return, elder or not etc...)