Try to avoid asking by email if at all possible. However, if you're in an unavoidable situation—for example, you or your teacher changed schools—then emailing is fine. Start by reminding them of who you are, and tell them something specific you liked about their class.
Be sure to include any links they may need. In most cases, once you have asked your teacher or counselor if they are willing to write a letter of recommendation, you will then submit the recommendation request via your application platform, like Common App. Your teacher or counselor will receive the request directly from the portal. You should confirm specific instructions for each institution or scholarship that you need a recommendation for. If the letter has to be sent through the mail, get their mailing address so that you can send them the information plus an addressed and stamped envelope.