Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter电子邮件库发送空白电子邮件或html源代码_Php_Codeigniter_Email_Codeigniter 3_Codeigniter Email - Fatal编程技术网

Php Codeigniter电子邮件库发送空白电子邮件或html源代码

Php Codeigniter电子邮件库发送空白电子邮件或html源代码,php,codeigniter,email,codeigniter-3,codeigniter-email,Php,Codeigniter,Email,Codeigniter 3,Codeigniter Email,我以前从未遇到过通过CodeIgniter发送电子邮件的问题,但突然之间,这成了我最新项目的一个问题 我用它在我的本地主机上发送邮件,这以前从未给过我任何问题,然后是CodeIgniter电子邮件库 我可以得到两个结果之一:要么是电子邮件发送,但显示所有原始HTML源代码;要么是电子邮件发送并有主题行,但整个正文为空 这是我的电子邮件\u helper.php <?php defined('BASEPATH') OR exit('No direct script access allowe

我以前从未遇到过通过CodeIgniter发送电子邮件的问题,但突然之间,这成了我最新项目的一个问题

我用它在我的本地主机上发送邮件,这以前从未给过我任何问题,然后是CodeIgniter电子邮件库

我可以得到两个结果之一:要么是电子邮件发送,但显示所有原始HTML源代码;要么是电子邮件发送并有主题行,但整个正文为空

这是我的
电子邮件\u 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();
}
<!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');

希望这对您有所帮助:

您的加载视图部分缺少
$data
,还可以尝试使用
$ci->load->library('email',$config')而不是
$ci->email->initialize($config)

send_email
应该是这样的:

function send_email($to, $subject, $template)
{
    $ci = & get_instance();

    $config = array(
      'mailtype'  => 'html',
      'charset' => 'iso-8859-1',
      'newline' => '\r\n',
      'crlf'  => '\r\n'
    );

    $data = '';

    $body = $ci->load->view('email/' . $template . '_html', $data, TRUE);
    echo $body; die;

    $ci->load->library('email', $config);
    $ci->email->set_mailtype("html");
    $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'));
    if ($to) 
    {
      $ci->email->to($to);

      $ci->email->subject($subject);
      $ci->email->message($body);
      if ($ci->email->send())
      {
        return TRUE;
      }
      else
      {
        echo $ci->email->print_debugger();die;
      }
    }
}

更多信息:

请尝试不使用doctype,并最终使用head tag,但不幸的是,该标记无效。没有任何错误,它成功发送,但正文仍然为空。当
echo$body;死亡在chrome开发工具中,我可以在回显主体时看到呈现的HTML。因此,这篇文章似乎工作正常。好吧,尝试添加这个
$ci->email->set_mailtype(“html”)
$ci->email->to$to之前成功了!真不敢相信!为什么在配置数组中设置mailtype时它不起作用,但它会直接起作用??可能是CI邮件类中的错误?