发送HTML电子邮件结果显示HTML源(Codeigniter电子邮件类) [英] Sending HTML Email results in Email displaying HTML source (Codeigniter Email Class)

查看:164
本文介绍了发送HTML电子邮件结果显示HTML源(Codeigniter电子邮件类)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Codeigniter中通过电子邮件类发送的电子邮件中出现问题,显示电子邮件消息中的源代码HTML而不是呈现的HTML视图。对于测试,我目前在Windows上使用XAMPP上的CI,并使用Gmail SMTP发送到同一个gmail地址。

I am having problems with email sent via the email class in Codeigniter displaying the source HTML code in the email message instead of the rendered HTML view. For testing, I am currently having CI on XAMPP on Windows, and using Gmail SMTP to send to the same gmail address.

发送电子邮件的功能如下:

The function that sends the email is as follows:

$config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'myaccountname@gmail.com',
        'smtp_pass' => 'mygmailpassword',
        );

    $this->load->library('email', $config); 
    $this->email->from($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
    $this->email->reply_to($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
    $this->email->to($email);
    $this->email->subject(sprintf($this->lang->line('auth_subject_'.$type), $this->config->item('website_name', 'tank_auth')));
    $this->email->message($this->load->view('email/'.$type.'-html', $data, TRUE));
    $this->email->set_alt_message($this->load->view('email/'.$type.'-txt', $data, TRUE));

    $this->email->set_newline("\r\n"); // require this, otherwise sending via gmail times out

    $this->email->send();

发送文本版本没有问题。加载的视图是一个将通过电子邮件发送的html文件。

There is no problem getting the text version sent. The view loaded is a html file that will be emailed out.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Welcome to <?php echo $site_name; ?>!</title></head>
<body>
<div style="max-width: 800px; margin: 0; padding: 30px 0;">
<table width="80%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="5%"></td>
<td align="left" width="95%" style="font: 13px/18px Arial, Helvetica, sans-serif;">
<h2 style="font: normal 20px/23px Arial, Helvetica, sans-serif; margin: 0; padding: 0 0 18px; color: black;">Welcome to <?php echo $site_name; ?>!</h2>
Thanks for joining <?php echo $site_name; ?>. We listed your sign in details below, make sure you keep them safe.<br />
To verify your email address, please follow this link:<br />
<br />
<big style="font: 16px/18px Arial, Helvetica, sans-serif;"><b><a href="<?php echo site_url('/auth/activate/'.$user_id.'/'.$new_email_key); ?>" style="color: #3366cc;">Finish your registration...</a></b></big><br />
<br />
Link doesn't work? Copy the following link to your browser address bar:<br />
<nobr><a href="<?php echo site_url('/auth/activate/'.$user_id.'/'.$new_email_key); ?>" style="color: #3366cc;"><?php echo site_url('/auth/activate/'.$user_id.'/'.$new_email_key); ?></a></nobr><br />
<br />
Please verify your email within <?php echo $activation_period; ?> hours, otherwise your registration will become invalid and you will have to register again.<br />
<br />
<br />
<?php if (strlen($username) > 0) { ?>Your username: <?php echo $username; ?><br /><?php } ?>
Your email address: <?php echo $email; ?><br />
<?php if (isset($password)) { /* ?>Your password: <?php echo $password; ?><br /><?php */ } ?>
<br />
<br />
Have fun!<br />
The <?php echo $site_name; ?> Team
</td>
</tr>
</table>
</div>
</body>
</html>

任何想法如何发送HTML电子邮件而不是显示其源代码?

Any ideas how to get HTML emails sent to be rendered instead of displaying its source code?

推荐答案

尝试将 mailtype 添加到config:

Try adding the mailtype to the config:

$config = Array(
    'mailtype' => 'html',
    ...etc...
);

请参阅 http://codeigniter.com/user_guide/libraries/email.html

这篇关于发送HTML电子邮件结果显示HTML源(Codeigniter电子邮件类)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆