我正在使用以下代码从我的基于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;
有没有人知道如何添加自定义电子邮件模板以保存我的简明表单信息?
答案 0 :(得分:20)
这是我做过的一个例子
$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
),然后将该视图页面分配给变量,然后使用该消息发送邮件
答案 1 :(得分:6)
首先需要将配置初始化为
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
加载电子邮件库后,您可以将电子邮件视图存储到变量并邮寄
$mailbody = $this->load->view('myfile', $data, true);
答案 2 :(得分:2)
您可以尝试
$this->load->helper(array('email'));
$this->load->library(array('email'));
$this->email->set_mailtype("html");