用CI發送郵件的Class 在中文標題太長的情況下會出現亂碼,解決方法如下: 打開 libraries/Email.php 找到:function subject($subject)
public function subject($subject)
{
$subject = $this->_prep_q_encoding($subject);
$this->_set_header('Subject', $subject);
return $this;
}
修改為:
public function subject($subject)
{
//$subject = $this->_prep_q_encoding($subject);
$subject = '=?'. $this->charset .'?B?'. base64_encode($subject) .'?=';
$this->_set_header('Subject', $subject);
return $this;
}
發送mail function :
function mail( ) {
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_user'] = 'XXXXXXXXXX@gmail.com';
$config['smtp_pass'] = 'XXXXXXXXXXXXX';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '5';
$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
$this->email->initialize($config);
$this->email->from('test@gmail.com');
$this->email->to('tess@hotmail.com');
$this->email->subject("標題太長標題太長標題太長標題太長標題太長標題太長標題太長標題太長標題太長標題太長標題太長");
$this->email->message('測試mail');
$this->email->send();
echo $this->email->print_debugger();
}
沒有留言:
張貼留言