Unless you are personally known to The King or The Queen or another member of the royal family you should address your letter to a Private Secretary, Equerry or Lady in Waiting, asking for the subject of the letter be known to His or Her Majesty.
In such cases the letter can begin and end:
Dear Sir or Dear Madam (if name not known)
Yours faithfully
Dear Sir Edward
Yours sincerely
Envelope: The Private Secretary to The King (for example).
For those who do wish to write directly to The King, the letter should begin ‘Sir’ or ‘May it please Your Majesty’. It ends with ‘I have the honour to remain, Sir, Your Majesty’s most humble and obedient subject’ and then your name.
For those who do wish to write directly to The Queen, the letter should begin ‘Madam’ or ‘May it please Your Majesty’. It ends with ‘I have the honour to remain, Madam, Your Majesty’s most humble and obedient subject’ and then your name.
Within the body of the letter do not use ‘you’ (singular) or ‘your’ (singular). Instead use ‘Your Majesty’ and ‘Your Majesty’s’.
Envelope: His Majesty The King or Her Majesty The Queen