如何发送电子邮件与来自代码中的视图的内容 [英] How to send an email with content from a View in codeigniter
本文介绍了如何发送电子邮件与来自代码中的视图的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的应用程式传送电子邮件给使用者,并从视图载入电子邮件的内容。这是我到目前为止试过的代码:
$ 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->库('email');
以及CI中的电子邮件。 / li>
- 此外,在您的代码中:
$ fromemail
未初始化。 - 您需要在服务器上具有 SMTP支持。
- $ config应声明为数组
<$> 工作代码: p $ p>$ this-> load-> library('email');
$ fromemail =ad@c.com;
$ toemail =user@email.id;
$ subject =Mail Subject is here;
$ mesg = $ this-> load-> view('template / email',true);
$ this-> load->库('email');
$ 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指出的 true 。通过将其设置为true,它不会将数据发送到输出流,但会作为字符串返回。I want to send an email to user from my application with the content of the email loaded from a view . This is the code i've tried out till now:
$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();
解决方案- You need to call
$this->load->library('email');
within the controller as well for the email in CI to work. - Also , in your code :
$fromemail
is not initialized. - You need to have SMTP support on your server.
- $config should be declared as an array before assigning values and keys.
Working Code:
$this->load->library('email'); $fromemail="ad@c.com"; $toemail = "user@email.id"; $subject = "Mail Subject is here"; $mesg = $this->load->view('template/email',true); $this->load->library('email'); $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();
Edit:
$mesg = $this->load->view('template/email',true);
should be having the true as pointed out by lycanian. By setting it as true , it doesn't send data to the output stream but it will return as a string.这篇关于如何发送电子邮件与来自代码中的视图的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- You need to call
查看全文