I am thinking that this isn't possible. I could be wrong but the way I see it, mIRC sees you trying to quit then it sends /quit Blah Blah Blah to the server. The quit reason can't respond to any raw message because by the time you receive it you are in your PJ's and on your knees saying your nightly prayers and therefore anything further that is sent when reacting to the last message received from the server is useless in this regard. As I said, I could be wrong as there may be some l337 way of scripting it but I can't think of anything that would work.
At the very least you would have to cover ON INPUT, covering both /quit, /exit and /disconnect as well as work out a way of making the same message send when using the ON/OFF button at top left and also the [X] at top right - a pain in the arse ay.