dongyun6003 2013-09-05 10:39
浏览 22

CodeIgniter发送带图像的电子邮件

I'm Beginner for the CI.

Here is my code in welcome.php

class Welcome extends CI_Controller {


public function index()
{
$this->load->helper('url');
    $this->load->view('welcome_message');
}
public function emailSend()
{
$this->load->library('upload');
$this->load->library('email');

$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$this->upload->initialize($config);







$this->email->from($this->input->post('from'), $this->input->post('name'));
$this->email->to('taryar.t1@gmail.com');
//$this->email->cc('another@another-example.com');
//$this->email->bcc('them@their-example.com');

$this->email->subject($this->input->post('subject'));
$this->email->message($this->input->post('body'));

if($this->upload->do_upload())
{
    $attachdata=$this->upload->data();
$this->email->attach($attachdata['full_path']);
}

if($this->email->send())
    {
        echo 'Your email was sent, successfully.';
    }

    else
    {
        show_error($this->email->print_debugger());
    }

}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

This code is only work for text and not for the attachment(image). The error is "Unable to send email using PHP mail(). Your server might not be configured to send mail using this method."

how can i fixed that error?? Help me Thz you.

  • 写回答

3条回答 默认 最新

  • douruye5092 2013-09-05 10:43
    关注

    Try this from the official docs..

    $this->email->attach('/path/to/photo1.jpg');
    $this->email->send();
    
    评论

报告相同问题?