Ti is used before verbs or it's attached to the verb, as in Ti scrivo una lettera (I write a letter to you), ti regalo una matita (I give you a pencil), portati un cappello! (Bring "yourself" a hat!), voglio regalarti una matita (I want to give you a pencil).
Te can either be used as a direct object after a verb:
Volevano te al telefono (They wanted you at the phone),
after a preposition:
Vado al cinema con te (I go to the cinema with you),
or before another pronoun:
Ti do il regalo. Te lo do. (I give you the gift. I give it to you).
Hope this helps!