2016-03-28 85 views
0

關於此問題,我已檢查堆棧溢出的類似鏈接。但我無法找到任何解決方案。附件不工作的Codeigniter電子郵件

Link的我已經檢查

  1. Codeigniter send email with attach file
  2. Code Igniter -> attach email
  3. codeigniter send pdf file as email attachment

問題

何時發送郵件,我收到郵件。與所有細節。但附件不起作用。

嘗試

我贊同的文件名,它從打印控制器中的文件名

代碼

$upcon['upload_path'] = 'cv_uploads/'; 
$upcon['max_size'] = '5120'; 
$upcon['allowed_types'] = 'pdf|doc|txt|zip|rtf|docx'; 
$this->load->library('upload', $upcon); 
if(!$this->upload->do_upload('file')){ 
    echo $this->upload->display_errors(); 
} 
else{ 
    $up_data = $this->upload->data(); 

    $config['protocol'] = 'sendmail'; 
    $config['mailpath'] = '/usr/sbin/sendmail'; 
    $config['mailtype'] = 'html'; 
    $config['charset'] = 'iso-8859-1'; 
    $config['wordwrap'] = TRUE; 

    $this->load->library('email',$config); 
    $this->email->set_newline("\r\n"); 

    $name = $this->input->post('name'); 
    $email = $this->input->post('email'); 
    $address = $this->input->post('address'); 
    $residence = $this->input->post('residence'); 
    $office = $this->input->post('office'); 
    $mobile = $this->input->post('mobile'); 
    $position = $this->input->post('position'); 
    $comment = $this->input->post('comment'); 

    $file_name= '/cv_uploads/'.$up_data['file_name']; 

    $this->email->from('[email protected]', 'site name'); 
    $this->email->to('[email protected]'); 
    $this->email->attach($file_name); 
    $this->email->subject('Subject'); 
    $this->email->message("Message "); 
    if(!$this->email->send()) 
    { 
     $data['sent_mail'] = false; 
    } 
    else{ 
     $data['sent_mail'] = "true"; 
    } 

    print_r($file_name); 
} 

我收到的郵件沒有附件。任何想法??

+0

添加絕對路徑,而不是相對路徑;) –

+0

@ManinderpreetSingh你能告訴我的代碼? –

+0

任何幫助?????? –

回答

1

要發送您的附件使用絕對路徑,而不是相對的,並確保您的附件可以公開訪問。

絕對路徑,例如

c:/test/test/cv_uploads/cv.doc 
在你的代碼

嘗試

$file_name= FCPATH.'/cv_uploads/'.$up_data['file_name']; 

$file_name= $_SERVER["DOCUMENT_ROOT"].'/cv_uploads/'.$up_data['file_name']; 

和附加文件,這個功能

$this->email->attach($file_name); 
+0

sry它是複製粘貼錯誤 –

+0

不工作。任何想法?? –

+0

你在本地工作嗎? –