I am using CodeIgniter to send mass mails to people on a school account. When the email returns "Mail Delivery Error", I want the error email to be sent to the school, and not to the $from address.
The sending and receiving of emails works fine, but is there a way for Codeigniter or PHP to catch the mail delivery error and send it to another email address?
Something like:
CodeIgniter - $this -> email -> mail_delivery
or PHP - mail_delivery_error()
The bounces are handled by the return path header of the mail. You can modify the header to point to the right location. This answer explains return path in detail. This answer explains how to do it in PHP
PHP has no visibility of the email after it has handed it over to the MTA. To make an intelligent bounce handler you first need to route the bounce messages back to a PHP script. Then your script needs to be able to identify the message as a bounce rather than a temporary failure or an unsollicited email and act on it accordingly.