The best bet would be to take a bus from Fatima to Coimbra and then the daily train from Coimbra to Salamanca!
There is a daily rede-expressos.pt coach service leaving Fatima at 21:00 arriving Coimbra at 21:55
There is a 23:37 daily departure from Coimba-B Station arriving Salamanca at 04:36.
You would need to take a taxi the 1km from the bus station to Coimbra-B station
You should also buy tickets in advance. Online, these can be acquired via the spanish train operator renfe.es