Hello and welcome!
I used to take the train from Puerto de Santa Maria to Malaga, if you choose this, the journey will take approximately 5 hours since you get into the first train. The journey from Rota to Puerto de Santa Maria by car is approximately 25 minutes.
You must take two trains, the first one to Seville and the second one from Seville to Malaga:
1-Train to Seville Santa Justa or Seville Dos Hermanas (15 minutes difference, Santa Justa is the last stop and Dos Hermanas the one before, it will take you 2 hours)
2-Train from any of those stations above to Malaga which is the last stop.