2016-04-07 134 views
3

这是我的代码发送HTML电子邮件,但它不能正常工作。电子邮件中只显示原始的html代码。html电子邮件不发送codeigniter

 $emailID = $this->input->post('email'); 
     $name = $this->input->post('name'); 

     $this->load->library('email'); 

     $config['protocol'] = 'smtp'; 
     $config['mailtype'] = 'html'; 
     $config['crlf'] = "\r\n"; 
     $config['wordwrap'] = TRUE; 
     $config['newline'] = "\r\n"; 
     $config['validate'] = FALSE; 

     $this->email->set_newline("\r\n"); 
     $this->email->from($emailID,$name); 
     $this->email->to('[email protected]'); 
     $this->email->subject('Email Testing'); 
     $this->email->message('from clientside mail'); 
     $this->email->send(); 

     $message = $this->load->view('emailfile/file','',TRUE);    
     $this->load->library('email', $config); 
     $this->email->from($emailID,$name); 
     $this->email->to($emailID,$name); 
     $this->email->subject('Email Testing'); 
     $this->email->message($message); 
     $this->email->send(); 
     //echo $this->email->print_debugger(); 
+0

什么是错误讯息?你能补充一点吗? –

+0

如果您的CI客户端上的电子邮件使用Gmail,请不要忘记在设置中允许它。或者,如果您尝试使用自己的@ website.com,请立即尝试使用Gmail以确保您的代码真正可用。有时你的虚拟主机电子邮件服务器坏了 – AchmadJP

回答

1

添加$this->email->initialize($config);

$this->load->library('email'); 
$config['protocol'] = 'smtp'; 
$config['mailtype'] = 'html'; 
$config['crlf'] = "\r\n"; 
$config['wordwrap'] = TRUE; 
$config['newline'] = "\r\n"; 
$config['validate'] = FALSE; 
$this->email->initialize($config); 
+0

非常感谢你的朋友。 –