2013-01-15 188 views
3

我在使用codeignitor電子郵件類發送帶有附件的HTML郵件時出現問題,該郵件顯示的是html代碼而不是html視圖。下面當我使用codignator電子郵件類發送電子郵件時顯示html源的電子郵件

我已經設置mailtype在配置HTML是我的代碼

$message="<p>test</p>"; 
$mail_to = "[email protected]"; 
$from_mail = $useremail; 
$from_name = $userfname; 
$reply_to = $useremail; 
$subject = "Abstract Details"; 



$file_name = $datamail['varafile']; 
$path = realpath('uploads/abstract'); 

// Read the file content 
$file = $path.'/'.$file_name; 

$config = array (
       'protocol' =>'sendmail', 
          'mailtype' => 'html', 
          'charset' => 'utf-8', 
          'priority' => '1' 
           ); 
     $this->load->library('email',$config); 


     $this->email->set_newline("\r\n"); 

     $this->email->from($from_mail,$from_name); 
     $this->email->to($mail_to);  
     $this->email->subject($subject);  
     $this->email->message($message); 
     $this->email->attach($file); 
     if($this->email->send()){ 
     echo "Mail send successfully"; 

     }else{ 
     echo "Error in sending mail"; 

     } 
+0

難道@Adam威斯布魯克回答你的問題?因爲你應該承認它。或者如果你想出來,你應該發佈你的解決方案。只是說,這就是它的工作原理。 –

回答

0

[向大家致歉,我沒有足夠的代表澄清評論]

我只是想你確切代碼(減去固定位)和所有工作正常發送HTML郵件的Gmail帳戶,我會提供我下面全工人階級:

class rohithipix extends CI_Controller { 

    public function html_email() { 

     $message = "<h1>start</h1><p>test</p>"; 
     $mail_to = "[email protected]"; 
     $from_mail = '[email protected]'; 
     $from_name = 'dave'; 
     $reply_to = '[email protected]'; 
     $subject = "Abstract Details"; 

     //$file_name = $datamail['varafile']; 
     //$path = realpath('uploads/abstract'); 

     // Read the file content 
     //$file = $path . '/' . $file_name; 

     $config = array(
      'protocol' => 'sendmail', 
      'mailtype' => 'html', 
      'charset' => 'utf-8', 
      'priority' => '1' 
     ); 
     $this->load->library('email', $config); 


     $this->email->set_newline("\r\n"); 

     $this->email->from($from_mail, $from_name); 
     $this->email->to($mail_to); 
     $this->email->subject($subject); 
     $this->email->message($message); 
     //$this->email->attach($file); 
     if ($this->email->send()) { 
      echo "Mail send successfully"; 
     } else { 
      echo "Error in sending mail"; 
     } 
    } 

} 

什麼電子郵件客戶端,你試圖仙d這些在測試時?

1

配置像這樣

$config = Array(
    'protocol' => 'sendmail', 
    'mailtype' => 'html', 
    'smtp_host' => '', //your SMTP host 
    'smtp_port' => 26, 
    'smtp_user' => '', //your SMTP email address 
    'smtp_pass' => '', //your SMTP email password 
    'charset' => 'iso-8859-1', 
    'wordwrap' => TRUE 
); 
$this->load->library('email', $config); 
$this->email->set_newline("\r\n"); 
$this->email->set_header('MIME-Version', '1.0; charset=utf-8'); //must add this line 
$this->email->set_header('Content-type', 'text/html'); //must add this line 

$this->email->from('', ''); //from/sender email [with name (optional)] 
$this->email->to(); //to/receiver email 

$this->email->subject(''); //email subject 
$message = $this->load->view('...directory.../...filename...',$data,TRUE); //html template/body with dynamic data 
$this->email->message($message); 
$this->email->send(); 
+0

$ this-> email-> set_header('MIME-Version','1.0; charset = utf-8'); $ this-> email-> set_header('Content-type','text/html'); 以上2行爲我工作:) – Shams

相關問題