Welcome to the forums! Hope the car hasn't been overheating regularly? With E39's it's a fairly common issue though, you'll be best off replacing some parts:
The same thing happened to my 525i last year sometime, the dealers set me back around R7k including a pressure test to make sure the head wasn't cracked. If you tell us where you based someone can recommend a workshop you can take the car to