Hamlet never gets to England. In Act 4, Scene 6, some Sailors hand-deliver a letter to Horatio in which Hamlet explains what has happened to him. His ship was attacked by a pirate ship. Very courageously he boarded enemy ship alone and became a captive when the ship pulled away. The bearers of the letter are obviously pirates and are after ransom. It is not clear whether Horatio ransoms Hamlet with his own money or gets money from King Claudius for that purpose. Hamlet may be said to have escaped death with the help of Horatio, since Hamlet appealed directly to him.
In Act 5, Scene 2, Hamlet explains to Horatio what happened to Rosencrantz and Guildenstern. It was before the pirate attack that Hamlet read the letter they were carrying to England requesting Hamlet's immediate beheading and signed and sealed by King Claudius.
Groped I to find out them; had my desire.
Finger'd their packet, and in fine withdrew
To mine own room again; making so bold,
My fears forgetting manners, to unseal
Their grand commission; where I found, Horatio,--
O royal knavery!--an exact command,
Larded with many several sorts of reasons
... no leisure bated,
No, not to stay the grinding of the axe,
My head should be struck off. (V.ii)
Hamlet tells Horatio how he forged a different letter requesting the immediate beheading of Rosencrantz and Guildenstern. If they had not been attacked by pirates, Hamlet would have ended up in England with his two former schoolmates. They would have been executed, as per Hamlet's instructions, without being given time to protest their innocence or to say anything about Hamlet's madness and his murder of Polonius--but Hamlet would still have been in a tight spot. How could he get back to Denmark? How could he account for the executions of Rosencrantz and Guildenstern? Claudius would eventually see the forged letter. The English would certainly not throw it away. No doubt, Claudius would receive a prompt reply from England announcing that his request to have Rosencrantz and Guildenstern executed had been carried out.
In the meantime, Hamlet would have had the good sense to get out of England. Would he have returned to Denmark knowing that Claudius wanted him killed? He does in fact return to Denmark--but Claudius has not yet received any report from England and undoubtedly assumes that Rosencrantz and Guildenstern are still alive and well, and he also undoubtedly assumes that Hamlet escaped execution by sheer happenstance and knows nothing about the contents of the original letter.