Passengers are being urged to only take essential train journeys to, from or within areas affected by extreme heat – as record June temperatures hit.