Tons of spells that grant you physical immunities.
The
Iron Body spell gets you a lot of immunities, though it has some significant downsides.
Spell Compendium has several similar spells that transform your body to something elemental or undead and grant you appropriate resistances and immunities (Body of War, Elemental Body, Veil of Undeath).
I also often used Contingency as a defensive spell that would pop a Resiliant Sphere on my mage under appropriate conditions.
That brings up a really good defense, "not being targetable." No line of sight/effect (fog/resilient sphere), not being able to be sensed by magic (non-detection/Mind Blank), and full on not being there (fighting via proxy with Eidolons, summoned/called monsters, Simulacra, Cohorts, mind flunkies etc).
Personally, I feel resistances/immunities are best set up before the fight. Once initiative is rolled and action economy comes into play, the best defense is defeating the other guy. Lol, that reminds me of Suicide Sam Orc barbarian that rolled out with a negative AC but hit like a truck, made of tungsten, dropped from orbit.