For many people (including, unfortunately, French people), this is a recurrent mistake, despite the fact it can be avoided easily.
Those endings are used for different things. The first one, '-er', is the infinitive form of the verb (for 1st group verbs, and some exceptions such as "aller"). To know if it is this form you need to use, a common technique given to children in France is to replace the verb you are using by 'prendre', to see whether you would keep the infinitive in the sentence, for example:
The correct form is: Je dois manger (not ‘mangé’) un sandwich
because you would say ‘Je dois prendre un sandwich (not 'pris'), so you need to use the infinitive.
The second ending, -é (or -ée in the feminine form, -és in the plural and -ées in the plural feminine form) is the past participate of the verb. You can use the same technique to distinguish it from ‘-er’:
The correct form this time is: J’ai mangé (not ‘manger’) un sandwich
because you would say ‘J’ai pris un sandwich’ (not ‘j’ai prendre’).
The third ending, -ez, is used only for the ‘vous’ form, either singular (polite ‘vous’) or plural, with either present indicative (Vous mangez.) or imperative (Mangez !). You just need to think about whether or not the verb you’re using is using this 2nd plural person.