简体   繁体   English

在codeigniter / php中的html电子邮件

[英]html email message in codeigniter/php

This has to be simple, I'm trying to load a view file as my email message using CodeIgniter. 这必须很简单,我正在尝试使用CodeIgniter将视图文件作为电子邮件加载。 The point is to have an HTML and not just a text-based message. 关键是要有HTML,而不仅仅是基于文本的消息。

Currently, my emails are sending ok but the messages are empty if my code looks like what it does below: 目前,我的电子邮件发送正常,但如果我的代码如下所示,则消息为空:

Here's the relevant part of the php: 这是php的相关部分:

    $config=array(
    'protocol' => 'smtp',
    'smtp_host' => 'xxx',
    'smtp_user' => 'xxx',
    'smtp_pass' => 'xxx',
    'smtp_port' => 587,
    'mailtype' => 'html',
    'crlf' => "\r\n",
    'newline' => "\r\n"
  );
 $this->email->initialize($config);
 $this->email->subject('testing loading a view file');
 $msg = $this->load->view('reviews/email', '', false);
 $this->email->message($msg);

Here's what the reviews/email.php file looks like: 这是reviews / email.php文件的外观:

<html>
<head></head>
    <body> <h1>this should be BIG</h1> this should not
          <a href="http://google.com/<? $php='login'; echo $php?>">Google</a>
    </body>
</html>

Thanks for any advice you might have, 感谢您的任何建议,

Tim 提姆

You're loading the view incorrectly. 您错误地加载了视图。 The third parameter is supposed to be TRUE so that CodeIgniter will return the view as a string. 第三个参数应为TRUE以便CodeIgniter将视图作为字符串返回。

$msg = $this->load->view('reviews/email', '', true);

From http://codeigniter.com/user_guide/general/views.html : http://codeigniter.com/user_guide/general/views.html

There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser. 第三个可选参数使您可以更改函数的行为,以便它以字符串形式返回数据,而不是将其发送到浏览器。 This can be useful if you want to process the data in some way. 如果您想以某种方式处理数据,这可能会很有用。 If you set the parameter to true (boolean) it will return data. 如果将参数设置为true(布尔值),它将返回数据。 The default behavior is false, which sends it to your browser. 默认行为是false,它将其发送到您的浏览器。 Remember to assign it to a variable if you want the data returned: 如果要返回数据,请记住将其分配给变量:

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

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

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