PHP Codeigniter: Is there an elegant way to to get the SMTP return code upon a mail failure
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 libshttp://codeigniter.com/user_guide/general/creating_libraries.html
If you're sending emails using sendmail
you may not be able to get the SMTP return codes until later.
The way to get bounces (I'm guessing?) is by adding a Return-Path
to your outgoing emails and choose an email inbox that's manned by procmail
, so that you can pipe the feedback emails back into PHP to parse it.
Let me know if you need more details on the above.