我有一个使用CodeIgniter的邮件功能的奇怪行为,我试图解释但无法理解或推断它。
我的功能就像
function _send_email($type, $email, &$data)
{
//original
$this->load->library('email');
$this->email->from($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
$this->email->reply_to($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
$this->email->to($email);
$this->email->subject("Test Message");
$this->email->message($this->load->view('email/'.$type.'-html', $data, TRUE));
$this->email->set_alt_message($this->load->view('email/'.$type.'-txt', $data, TRUE));
$this->email->send();
}
这基本上受到了Tank Auth库的启发
当我在下面的方法中使用此功能时,会发送邮件:
function comment($postid=0){
$poster = $this->Post->getPoster($postid); # Gets the Post author records
$notifythisuser = $poster[0]['email']; # Gets the Post author's email
$datacode = array('posttitle' => $this->input->post('posttitle',true),
'posttext' => $this->input->post('posttext',true)
);
$this->_send_email('commentadded', $notifythisuser, $datacode);
$this->post->comment();
}
现在,在发送评论后通知用户更合理
所以函数将是
function comment($postid=0){
$poster = $this->Post->getPoster($postid); # Gets the Post author records
$notifythisuser = $poster[0]['email']; # Gets the Post author's email
$datacode = array('posttitle' => $this->input->post('posttitle',true),
'posttext' => $this->input->post('posttext',true)
);
if ($this->input->post('posttitle') ){
$this->post->comment();
$this->_send_email('commentadded', $notifythisuser, $datacode);
}
}
没有什么复杂的我只是重新安排了代码,以便在发布评论后发送通知,comment()
函数非常基本,它只是一个在注释表中执行insert
的函数
我试图调试邮件功能,没有发送错误,没有生成日志,有些错误但我不知道是什么
任何想法?
由于
答案 0 :(得分:0)
这是我的理论:
Codeigniter的输入类正在剥离posttitle
中类似xss的字符,它可能会留下一个空字符串。然后PHP通过假设空字符串为false来启动其弱类型。
if(""){
//THIS WILL NEVER EXECUTE BECAUSE PHP IS AWESOME
}
解决方案,使用强类型比较
if($this->input->post('posttitle') !== false){
$this->post->comment();
$this->_send_email('commentadded', $notifythisuser, $datacode);
}