PHP Codeigniter: Is there an elegant way to get SMTP return code when mail fails

When using standard Codeigniter

mail->send() 

it returns only TRUE or FALSE. However, I have requirements for handling some SMTP return codes in different ways. I can parse the debug text information or try to override the mail handler for Codeigniter. Is there a direct and elegant way to do this?

Thanks in advance.

+4
source share
2 answers

I do not think that CodeIgniter has a build mechanism. What you can do is extend the CI email class and add a function to protect the _debug_msg protected array.

If you look at the source of the email class, you will see that the print_debugger() function converts the _debug_msg array to a string. Therefore, if _debug_msg has what you are looking for, you do not have to parse any string.

 class MY_Email extends CI_Email { public function __construct() { parent::__construct(); } public get_msg() { if (count($this->_debug_msg) > 0) { return $this->_debug_msg; } else { return FALSE; } } } 

Refer to the following link on how to extend the CI libraries http://codeigniter.com/user_guide/general/creating_libraries.html

+3
source

If you send emails using sendmail , you will not be able to receive the SMTP return codes to the end.

How to get bounces (I guess?) By adding Return-Path to your outgoing emails and select the email inbox that procmail equipped with so that you can redirect feedback emails to PHP analyze it.

Let me know if you need more information about this above.

+2
source

All Articles