The DTP vaccine works by stimulating the immune system to produce antibodies against the bacteria that cause diphtheria, tetanus, and pertussis. When vaccinated, the body is exposed to inactivated toxins or parts of the bacteria, which are not capable of causing disease but can trigger an immune response. This prepares the body to recognize and fight the real bacteria if exposed in the future.