Rail is not an option!
Small matter of few train links between Portugal and Spain, the Straits of Gibraltar and yet to be developed submersible trains/rail tunnel to be built.
Basically you will have to head by coach to Tarifa/Algeciras in Spain or by a scheduled flight with a major airline or as from 2nd November 2010, nip up to Porto and get ryanair.com from Porto to Marrakesh.
These old articles on my blog may also be off interest.
http://bit.ly/dDmFsb