was told by the teacher thatThe と marks the content of what was said, and 言われた is the passive form of 言う, meaning that the speaker was told something. The subject of the quoted statement is usually understood from context.
JA: 宿題を忘れないようにと先生に言われた。
EN: I was told by the teacher not to forget my homework.