PHP Codeigniter: Is there an elegant way to to get the SMTP return code upon a mail failure
codeigniter, php, smtp
Solution
I dont think there is a build in mechanism for this in CodeIgniter. What you could do is extend the CI email class and add a function to expose the protected `_debug_msg` array.
If you look at the source of email class you will see that `print_debugger()` function is converting `_debug_msg` array into string. So if `_debug_msg` has what you are looking for then you wouldn't 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 the following link on how to extend CI libs http://codeigniter.com/user_guide/general/creating_libraries.html
Problem
When using the standard Codeigniter ``` mail->send() ``` it only returns TRUE or FALSE. However, I have requirements to handle certain SMTP return codes differently. I could parse out of the debug text info, or somehow try to override the mail handler for Codeigniter. Is there any straight forward and elegant way to do this? Thanks in advance.