I’m trying to find a way to add additional parameters to an email using Codeigniters email class (with the mail() send method). There is no documentation or other information I can find. Do you folks know if there is a way within the framework?
PHP native mail():
mail ( string $to , string $subject , string $message [, string $additional_headers
[, string $additional_parameters ]] );
Codeigniter:
$this->load->library('email');
$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->additional_parameters('something_goes_here'); // this is what I need
$this->email->send();
CodeIgniter’s Email Library is just a wrapper for PHP’s mail().
If you dig into the core and inspect
system/libraries/Email.php,_send_with_mail()is the function that kicks-off PHP’s nativemail().The current implementation under safe mode uses:
The current implmentation without safe mode uses:
Neither of which allow user-defined content to fill the
$additional_parametersvariable. You’ll need to extend theCI_Emailclass to accomplish this:In
application/libraries/create a fileMY_Email.phpwith contents:Now, to use it:
$this->email->additional_params('something_goes_here');When you call
$this->email->send(), this function will take over and append the parameters!Haven’t tested any of this. But this is the general idea. Hope it helps.