简体   繁体   English

使用 phpmailer 和 codeigniter 发送 html email

[英]Sending an html email with phpmailer and codeigniter

I am sending emails with phpmailer package and using the package with codeigniter framework.我正在使用 phpmailer package 发送电子邮件,并将 package 与 codeigniter 框架一起使用。 I have made a helper function out of the phpmailer package which takes arguments as sender's address, recipient's address, subject and message body.我从 phpmailer package 中制作了一个助手 function ,它以 arguments 作为发件人的地址、收件人的地址、主题和邮件正文。 Everything goes fine and the message is delivered to the inbox.一切顺利,邮件被发送到收件箱。
My problem is I have a large body which can be a seperate html file.我的问题是我的身体很大,可以是单独的 html 文件。 For this I have created a view and I am trying to send the argument $this->load->view('viewname');为此,我创建了一个视图,并尝试发送参数 $this->load->view('viewname'); through the helper function in my controller.通过我的 controller 中的助手 function。 But instead of displaying the body in mail I get the file displayed on my final view page and the mail body goes blank.但是,我没有在邮件中显示正文,而是将文件显示在我的最终视图页面上,并且邮件正文变为空白。 Any idea how I can achieve知道如何实现

Using $this->load->view('viewname');使用$this->load->view('viewname'); without any additional parameters will output the view.没有任何附加参数将 output 查看。 What you need is to set the third parameter to TRUE as suggested in the Returning views as data of the CodeIgniter User Guide's View documentation .您需要按照CodeIgniter 用户指南的查看文档的数据返回视图中的建议将第三个参数设置为TRUE

Example:例子:

$string = $this->load->view('viewname', '', true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM