Posted this info on another forum, posting it here also for train travellers.
Have received some inquiries regarding this subject so I'll try to clarify.
There's NO direct train between Lisbon and Madrid, online info is old and refers to a train that's no longer running.
There are two trains between Portugal and Spain.
One is from Porto Campanhã ( Portugal) to Vigo Guixar ( Spain).
The CP.PT site redirects to the Spanish train site Renfe.com
https://venta.renfe.com/vol/buscarTrenEnlaces.do?c=_0Y5k
The other train is from Lisbon ( Portugal) to Badajoz (Spain), this train is not direct and requires transfer at Entroncamento (Portugal).
The last train stop on this line in Portugal is Elvaz ( not to be confused with Évora), the following and last stop is Badajoz, from there transfers can be made for the trains to Seville or Madrid ( Spain) on the Renfe site.
The tickets for this train between Lisbon and Badajoz can be purchased on the CP.PT site.
https://www.cp.pt/passageiros/en/how-to-travel/For-leisure/Nature-and-Culture/train-to-badajoz
This additional info from another poster ,Cubsur, that has his own webpage.I will add that both the trains mentioned above run only twice each day. RENFE operates the Porto to Vigo trains. Tickets must be purchased on their website or at Porto Campanhã station. There are no other connections. RENFE stopped running its local trains across the border two years ago.
The trip via Entroncamento, Elvas and Badajoz is only for the brave! I have compiled some information at http://www.algarvebus.info/Elvas.htm - I went only as far as Elvas. You need separate tickets for the Portuguese and Spanish legs of such a trip.
This page I put together may also be useful - http://www.algarvebus.info/PDF/Seville-Lisbon-by-train.pdf