7

我正在使用下面的代码从基于 codeigniter 的网站的联系表发送电子邮件,为此我在控制器中使用以下代码,

    $entrydata['name']= $this->input->post('name');
    $entrydata['email']= $this->input->post('email');
    $entrydata['phone']= $this->input->post('phone');
    $entrydata['message']= $this->input->post('message');$msg = 'Email has sent successfully';

            $data['reset'] = TRUE;
            $this->load->library('email');
            $this->email->from(set_value('email'), set_value('name'));
            $this->email->to('my@webs.com');
            $this->email->subject("Get a quote enquiry");
            $all = 'Name:' . set_value('name') ."\n". 'Email :' .' '. set_value('email') ."\n".'Phone :' .' '. set_value('phone') ."\n".'Message :' .' '. set_value('message'); $this->email->message($all);
            $s=$this->email->send();
            $data['message'] = $msg;

有谁知道如何添加自定义电子邮件模板来保存我的联系表格信息?

4

3 回答 3

21

这是我做过的一个例子

 $data['map_to']=$this->input->post('map_to');
        $event=$this->db->query("query");
        if($event->num_rows()>0)
        {
            $data['event']=$event->row();
            $data['map_from']=$event->row()->address2;
        }
        else
        {
        $data['event']=NULL;    
        }
      $data['sender_mail'] = 'xx@xx.org';

        $this->load->library('email');
        $config = array (
                  'mailtype' => 'html',
                  'charset'  => 'utf-8',
                  'priority' => '1'
                   );
        $this->email->initialize($config);
        $this->email->from($data['sender_mail'], 'xxxx');
        $this->email->to($mail);
        $this->email->subject('Map Location');
        $message=$this->load->view('map_mail_format',$data,TRUE);
        $this->email->message($message);
        $this->email->send();       

在这里,我正在加载一个名为的视图页面map_mail_format并将值传递给该视图页面($data),然后将该视图页面分配给一个变量,然后发送带有该消息的邮件

于 2013-04-30T10:54:00.590 回答
6

首先,您需要将配置初始化为

$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);

加载电子邮件库后,您可以将电子邮件视图存储到变量并邮寄

$mailbody = $this->load->view('myfile', $data, true);
于 2013-04-30T10:56:33.503 回答
2

你可以试试这个

$this->load->helper(array('email'));
$this->load->library(array('email'));
$this->email->set_mailtype("html");
于 2014-02-11T20:07:37.270 回答