Tossing a tennis ball up a few feet so you can hit your serve seems as if it should be the easiest part of the whole game, but many players find it one of the more elusive skills.
The biggest source of difficulty stems from the fact that the most natural tossing motion, swinging the ball upward with a straight arm, requires an early and exactly timed release that can break down under pressure. If your arm is straight and you rotate your shoulder joint upward to execute the toss, your arm acts like one of the vanes on a windmill, with your shoulder as the hub. Someone standing on your baseline, watching you from the side as you swing the ball forward, then up, would see the ball describing part of a circular path in the air.
Depending on when you release the ball, it could go forward, straight up, or back, which can also put it to your right or your left, depending on how the circular path is oriented. It's generally a good idea to release the ball relatively late, so that your tossing hand is closer to where you want the ball to end up; a shorter toss has less room to go astray. With a circular tossing motion, though, the later you release the ball, the more it will go behind you. To get a circular tossing motion to result in a straight toss, you have to release the ball early, but not a moment too early. Many players manage to do this well most of the time, but when they get into tense situations, their timing goes off, and their tosses fly unpredictably, with disastrous consequences for their serves.
The solution is to use a tossing motion that may seem somewhat awkward at first, where you start the ball just in front of the leading edge of your right leg (for a right-hander). Instead of swinging the ball out, then up, in a circular path, slant the ball upward and forward on a straight line toward your intended point of contact for the serve. It sometimes helps to imagine that you're guiding the ball up through a pipe that goes to your point of contact. Your arm will look and feel mostly straight during your toss, but you'll naturally bend your elbow slightly in the early part of the tossing motion in order to move the ball in a straight line.