【发布时间】:2018-12-29 18:46:24
【问题描述】:
我以前通过 CodeIgniter 发送电子邮件从来没有遇到过问题,但突然之间,我的最新项目出现了问题。
我使用这个mail server tool 在我的本地主机上发送邮件,这之前从未给我带来任何问题,然后是 CodeIgniter 电子邮件库。
我可以得到以下两种结果之一: 电子邮件发送,但显示所有原始 HTML 源代码,或者电子邮件发送并有主题行,但整个正文为空白。
这是我的email_helper.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
function send_email($to, $subject, $template)
{
$ci = &get_instance();
$ci->load->library('email');
$config = array(
'mailtype' => 'html',
'newline' => '\r\n',
'crlf' => '\r\n'
);
//If I comment out this line, it sends raw HTML, otherwise it sends a blank body.
$ci->email->initialize($config);
$ci->email->from($ci->config->item('from_email_address'), $ci->config->item('from_email_name'));
$ci->email->reply_to($ci->config->item('from_email_address'), $ci->config->item('from_email_name'));
$ci->email->to($to);
$ci->email->subject($subject);
$ci->email->message($ci->load->view('email/' . $template . '_html', $data, TRUE));
$ci->email->send();
}
这是我的test_html.php
<!DOCTYPE html>
<html>
<head><title>Test</title></head>
<body>
<div style="max-width: 800px; margin: 0; padding: 30px 0;">
TEST!
</div>
</body>
</html>
然后我从我的控制器调用电子邮件助手:
$this->load->helper('email_helper');
send_email($this->input->post('email'), 'Test Subject', 'test');
【问题讨论】:
-
尝试不使用 doctype 并最终使用 head 标签
-
不幸的是没有用。
标签: php codeigniter email codeigniter-3 codeigniter-email