电子邮件附件不在codeigniter中工作

时间:2015-09-02 12:12:01

标签: codeigniter

附件文件的邮件功能在codeigniter中不起作用,我没有收到任何带附件的邮件..在我收到没有附件的邮件之前但我使用了“$ _SERVER [”DOCUMENT_ROOT“]之后。”/ admin / assets / image /order_complete_file/".$image_name;“,我没有收到任何邮件..请帮助我..这里我的编码是

$image_name = "some_name";
$content = "some content";
$subject = "Subject Name";          
$this->load->helper('email');
$this->load->library('email');
$this->email->set_newline("\r\n");
$this->email->from('abc@gmail.com');
$this->email->to('xxx@gmail.com');
$this->email->subject($subject);
$this->email->message($content);
$attched_file = $_SERVER["DOCUMENT_ROOT"]."/admin/assets/image/order_complete_file/".$image_name;
$this->email->attach($attched_file);
$this->email->send();

1 个答案:

答案 0 :(得分:1)

您应该为email库使用config参数,并将'mailtype'设置为'html'(默认值为'text')。如果仍然失败,您应该使用print_debugger()函数来查看原因。

    $config = Array( 
          'mailtype' => 'html'
        );
$image_name = "some_name";
$content = "some content";
$subject = "Subject Name";   
$this->load->library('email'); 

$this->email->initialize($config);

$this->email->from('abc@gmail.com');
$this->email->to('xxx@gmail.com');
$this->email->subject($subject);
$this->email->message($content);
$attched_file = $_SERVER["DOCUMENT_ROOT"]."/admin/assets/image/order_complete_file/".$image_name;
$this->email->attach($attched_file);
 if($this->email->send()){ echo 'Email send.';}
 else {show_error($this->email->print_debugger()); }