2015-10-24 43 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

相关问题