As you know say and tell are very similar in meaning. Stoney B has given a very good grammatical explanation already, but when you speak it's sometimes easier to think in terms of what you want to say.
Since the grammar has already been explained, I'll just give a couple of examples of what I mean.
With the veb say, the focus is on what is said or the information.
Example: He said the movie was amazing.
In this example, we can only assume he was talking to the speaker. But it's very possible he was talking to someone else, and the speaker simply heard him. The focus here is on the information. It must come directly after the verb say.
With the veb tell, the focus is on whom we tell or the listener.
Example: He told his students they had homework.
In this example, the information is present, but the most important part is the listeners, the students. When we use tell, the person or people to whom we are talking must come directly after the verb tell.