简体   繁体   中英

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. The point is to have an HTML and not just a text-based message.

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:

    $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:

<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.

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

From 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. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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