Iran has 3 million illegal immigrants, FYI. (Or had; they recently implemented mass deportations.)
Immigration inflow is caused by lax border control, not by being a great place to live. No matter how bad it is, there's always someone worse off willing to try their luck.
3 million from where? Is that by any chance refugees from the collapse of nearby Syria?