In very, very simple terms...
The brain is made up of billions of neurons (brain cells). Each neuron is 'connected' to thousands of other neurons. The neurons take input from all of their neighboring neurons, and if the input is enough they 'fire' sending an output to all of their neighboring neurons. This process leads to thought, cognition, etc... (Very simplified)
There is space between the neurons. When you take a drug, the drug gets into the spaces between the neurons and alters how/when the neuron fires. (Very simplified)
The neurons have receptors, which are a lot like a keyhole. Think of a drug as a key. The drug usually only effects a neuron if it fits into one of the neurons receptors.
A tryptamine has a shape very similar to serotonin. Because of this, it will fit into the same 'keyhole' that serotonin fits into... but because the tryptamine shape is a bit different, the effects are different.
For a more scientific explanation see How do shrooms work?.