I ended my recent trip to Morocco by taking the train from Marrakech back to Casablanca and the international airport.....a 3.5 hour journey door to door. First class ticket is about $18 USD....much less expensive that flying and you will see much more of the countryside. If you are going to the international airport, a train transfer is necessary (at Casa Oasis Station), but very easy.
This newer station is modern, clean and centrally located in Marrakech for easy access. The train system in Morocco is very inexpensive and a great way to get around. Seems like the trains are very punctual in this country, so arrive a bit early to purchase your ticket.
If you are in Morocco, I highly recommend trying the rail system.....a fun experience in my opinion!