2015-10-24 70 views
1

我試圖在通過我的項目發送郵件時將圖像附加到我的電子郵件中......到目前爲止,我正在成功地從下面的代碼發送電子郵件。是我應該使用添加附件到這個(添加圖像)的變化......請幫我用cordelgniter如何在發送電子郵件時附上圖像php

public function sendMailToComplete($ID) { 
     $this->load->model('get_db'); 
     $customers = $this->get_db->getBirthdays(); 
     $this->get_db->updateGreetingStatus(); 
     if (empty($customers)) { 
      return; 
     } 
     foreach ($this->get_db->getEmailConfig() as $row) { 
      $config = array(
       'protocol' => $row->protocol, 
       'smtp_host' => $row->host, 
       'smtp_user' => $row->user, 
       'smtp_pass' => $row->pass, 
       'smtp_port' => $row->port, 
       'smtp_timeout' => $row->timeout, 
       'mailtype' => $row->mailtype, 
       'charset' => $row->charset 
      ); 
      $this->load->library('email', $config); 

      foreach ($customers as $customer) { 
       $email = $customer['email']; 

       $this->email->clear(); 
       $this->email->set_newline("\r\n"); 
       $this->email->from($row->from, 'ABC'); 
       $this->email->to($email); 
       $this->email->subject('Birthday Greetings'); 
       $this->email->message('Many Happy Returns of the day...'); 
       $this->email->send(); 
      } 

      $this->email->clear(); 
     } 
    } 
function getBirthdays() 
     { 
      $query = $this->db->query("select ci.* from customer_info ci where month(b_day) = month(curdate()) and day(b_day) = day(curdate());"); 
      return $query->result_array(); 
     } 
+1

滾動到https://ellislab.com/codeigniter/user-guide/libraries/email.html底部 – JimL

+0

哦謝謝你我會試試這個.. – Akisha

+0

不..我試過這個,但這是沒有附加任何圖像到我的電子郵件 – Akisha

回答

0

你應該看看PHPMailer的庫來改變我的code.I'm

示例

$email = new PHPMailer(); 
$email->From  = '[email protected]'; 
$email->FromName = '[email protected]'; 
$email->Subject = $subject; 
$email->Body  = $msg; 
$email->AddAddress($to); 
$email->IsHTML(true); 


if($_FILES['fUpload']['tmp_name'][0] !== '' 
&& preg_match("/image/", $_FILES['fUpload']['type'][0])){ 

$file_to_attach = $_FILES['fUpload']['tmp_name'][0]; 
$email->AddAttachment($file_to_attach , $_FILES['fUpload']['name'][0]);   
} 

$sent = $email->Send(); 

https://github.com/PHPMailer/PHPMailer

+0

爲什麼他應該使用PHPMailer而不是Codeigniter中已有的? – JimL

+0

謝謝你的親切指導..我剛剛發現了一個錯誤,當我試圖根據JimL給予的指導發送附件,它只是爲我工作..謝謝你.. :) – Akisha

相關問題