如果你深入内核并检查system/libraries/Email.php
,_send_with_mail()
是启动 PHP 原生的函数mail()
。
安全模式下的当前实现使用:
mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str)
当前没有安全模式的实现使用:
mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From'])
两者都不允许用户定义的内容填充$additional_parameters
变量。您需要扩展CI_Email
该类来完成此操作:
在application/libraries/
创建一个MY_Email.php
包含内容的文件:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Email extends CI_Email{
public $additional_params = "";
function __construct(){
parent::__construct();
}
function additional_params($ap){
$this->additional_params = $ap;
}
protected function _send_with_mail(){
if ($this->_safe_mode == TRUE){
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, $this->additional_params)) return FALSE;
else return TRUE;
}
else{
if ( ! mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, "-f ".$this->clean_email($this->_headers['From']) . " " . $this->additional_params)) return FALSE;
else return TRUE;
}
}
}
现在,要使用它:
$this->email->additional_params('something_goes_here');
当您调用 时$this->email->send()
,此函数将接管并附加参数!
没有测试过这些。但这是一般的想法。希望能帮助到你。