2017-08-29 190 views
0

我的問題是:在Codeigniter中發送帶附件的電子郵件3.1.5 我想通過用戶發送名稱,電子郵件,電話和PDF文件作爲附件發送到電子郵件的表單,但我遇到問題。請幫我帶附件的codeigniter電子郵件

形式:

<div> 
     <label for="name" class="label">Name:</label> 
     <input type="text" name="name"> 
    </div> 

    <div> 
     <label for="email" class="label">Email:</label> 
     <input type="email" name="email"> 
    </div> 

     <div> 
      <label for="email" class="label">Phone:</label> 
      <input type="text" name="phone"> 
     </div> 

     <hr> 
    <div> 
     <label for="file">File: </label> 
     <input type="file" name="file"> 
    </div> 

     <hr> 
    <button type="submit" name="submit" class="button is-danger" >Send Form</button> 
    </div> 

    <?php echo form_close(); ?> 

這是控制器的形式返回

控制器:

公共職能的send(){

$config = [ 
     'porotocol' => 'sendmail', 
     'smtp_host' => 'data', 
     'smtp_port' => 993, 
     'smtp_user' => 'email', 
     'smtp_pass' => 'password', 
     'mailtype' => 'html', 
     'charset' => 'utf-8', 
     'wordwrap' => TRUE, 
    ]; 

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

    $data = [ 
     'name' => $this->input->post('name'), 
     'email' => $this->input->post('email'), 
     'phone' => $this->input->post('phone'), 
    ]; 

     $this->email->from($data['email'], $data['name']); 
     $this->email->to('[email protected]'); 
     $this->email->subject('form'); 

    $file_name= $this->input->post('file'); 
    $this->email->attach($file_name); 

     $message = $this->load->view('forms/formformat', $data, TRUE); 
     $this->email->message($message); 

    if($this->email->send()){ 
     $this->session->set_flashdata("email_sent","ok"); 
     redirect('forms/mailform'); 
    } else { 
     $this->session->set_flashdata("email_nosent","error"); 
     $data['content'] = 'forms/mailform'; 
     $this->load->view('master', $data); 
    } 

} 

而且我曾嘗試過上傳天秤座但是問題沒有解決。 你能幫我一下嗎?我可以通過附件發送郵件給我。 謝謝

+0

你需要在本地上載,然後附加到電子郵件https://stackoverflow.com/questions/43340427/codeigniter-3-email-attachment-from -形成 – qwertzman

回答

0

解決了我這個代碼:

 $aConfig['upload_path']  = './uploads/'; 
     $aConfig['allowed_types'] = 'pdf'; 
     $aConfig['max_size']  = '3000'; 
    $config['encrypt_name']  = true; 
     $this->load->library('upload', $aConfig); 


    foreach ($_FILES as $key => $file) 
    { 
     if ($file['error'] == 0) 
     { 
      $this->email->attach($file['tmp_name'], '', $file['name']); 
     } 
    }