我想从我的从视图中加载的电子邮件的内容的应用程序发送电子邮件给用户。 这是我尝试了到现在为止的代码:
$toemail = "user@email.id";
$subject = "Mail Subject is here";
$mesg = $this->load->view('template/email');
$this->load->library('email');
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->to($toemail);
$this->email->from($fromemail, "Title");
$this->email->subject($subject);
$this->email->message($mesg);
$mail = $this->email->send();
- 你需要调用
$this->load->library('email');
控制器以及在CI的电子邮件中工作。 - 此外,在您的代码:
$fromemail
未初始化。 - 您需要在您的服务器上的SMTP支持 。
- $配置应该被宣布为指定的值和键之前的数组。
工作守则:
$this->load->library('email');
$fromemail="ad@c.com";
$toemail = "user@email.id";
$subject = "Mail Subject is here";
$data=array();
// $mesg = $this->load->view('template/email',$data,true);
// or
$mesg = $this->load->view('template/email','',true);
$config=array(
'charset'=>'utf-8',
'wordwrap'=> TRUE,
'mailtype' => 'html'
);
$this->email->initialize($config);
$this->email->to($toemail);
$this->email->from($fromemail, "Title");
$this->email->subject($subject);
$this->email->message($mesg);
$mail = $this->email->send();
编辑: $mesg = $this->load->view('template/email',true);
应具有lycanian指出, 真正为。 通过将其设定为真,它不发送数据到输出流,但它会返回一个字符串。
编辑: $this->load->view();
需要的数据的第二参数或清空等$mesg = $this->load->view(view,data,true);
如果不是它不会工作
这条线$ MESG = $这个- >负载>视图( '模板/电子邮件',TRUE); 应该是这样的
$ MESG = $这个- >负载>视图( '模板/电子邮件', '',TRUE);
与前值的单引号真实的,它会很好地工作
电子邮件模板发送CI中,我们需要在发送电子邮件之前把和meta标签
$this->data['data'] = $data;
$message = $this->load->view('emailer/create-account', $this->data, TRUE);
$this->email->set_header('MIME-Version', '1.0; charset=utf-8');
$this->email->set_header('Content-type', 'text/html');
$this->email->from($email, $name);
$this->email->to('emailaddres@mail.com');
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
ü会尝试! 它的工作为我面临着许多错误后
$subject = 'New message.';
$config = Array(
'protocol' => 'sendmail',
'smtp_host' => 'Your smtp host',
'smtp_port' => 465,
'smtp_user' => 'webmail',
'smtp_pass' => 'webmail pass',
'smtp_timeout' => '4',
'mailtype' => 'html',
'charset' => 'utf-8',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->set_header('MIME-Version', '1.0; charset=utf-8');
$this->email->set_header('Content-type', 'text/html');
$this->email->from('from mail address', 'Company name ');
$data = array(
'message'=> $this->input->post('message')
);
$this->email->to($toEmail);
$this->email->subject($subject);
$body = $this->load->view('email/sendmail.php',$data,TRUE);
$this->email->message($body);
$this->email->send();