Add additional header information to codeigniter email address

I would like to send additional information about letters sent from the codeigniter library. Is there any way to customize or add this?

I want to classify all outgoing mail from my site. I need to include the sendgrid category header for tracking.

+6
source share
3 answers

The CodeIgniter email class does not allow you to set headers manually. However, you can change this by expanding it and adding a new function that allows you to set sendgrid headers.

See the Extension of Native Libraries section of the CodeIgniter manual:
http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html
Here's what the code looks like in your new email class.

class MY_Email extends CI_Email { public function __construct(array $config = array()) { parent::__construct($config); } public function set_header($header, $value){ $this->_headers[$header] = $value; } } 

You can then set the headers using the new email class, like this:

 $this->email->set_header($header, $value); 

This page explains which headers can be sent to SendGrid: http://sendgrid.com/docs/API%20Reference/SMTP%20API/

+10
source

Ok, I just want to improve the best answer here. The loan goes to @Tekniskt, and the only difference here is that the parameters that you may have in /application/config/email.php are ignored, which hurts, especially if you use the STMP user settings.

Here is the complete code for the MY_Email.php class, which I improved from the answer above:

 class MY_Email extends CI_Email { public function __construct($config = array()) { if (count($config) > 0) { $this->initialize($config); } else { $this->_smtp_auth = ($this->smtp_user == '' AND $this->smtp_pass == '') ? FALSE : TRUE; $this->_safe_mode = ((boolean)@ini_get("safe_mode") === FALSE) ? FALSE : TRUE; } log_message('debug', "Email Class Initialized"); } // this will allow us to add headers whenever we need them public function set_header($header, $value){ $this->_headers[$header] = $value; } } 

Hope this helps! :)

I performed my test, and now it seems that /config/email.php is turned on and the settings are passed properly.

Greetings and thanks for the answer! :)

+6
source

Pass the $config parameter

 class MY_Email extends CI_Email { public function __construct(array $config = array()) { parent::__construct($config); } public function set_header($header, $value) { $this->_headers[ $header ] = $value; } } 

Set the custom title as

 $this->email->set_header($header, $value); 
+1
source

Source: https://habr.com/ru/post/907217/


All Articles