we have a php mailing list script that work fine

now, we would like add new function for get smtp error and take correctly action.

for example:
if error is "bad destination mailbox address" don't try again to sent
if error is "Mailbox full" try later.. after x hours..

what is best way to check error and made action ??