There aren't a lot of templates for this online. You could consider employing a professional letter writer, but it is probably better to write it yourself. Just explain clearly what you have learned from your mistakes and what you will bring to the company if they give you another chance. Then you could give it to a professional copy editor to check the structure and spelling.