Php CodeIgniter-通过ajax和CodeIgniter电子邮件库向controller发送内容

Php CodeIgniter-通过ajax和CodeIgniter电子邮件库向controller发送内容,php,mysql,codeigniter,email,Php,Mysql,Codeigniter,Email,我有一个应用程序,其中我有一个wysiwyg编辑器来设计电子邮件并将其发送到数据库中的联系人,我有电子邮件功能,就像我使用发送到数据库联系人的输入表单进行测试一样,然而,我试图通过ajax将所见即所得编辑器中的内容传递给我的控制器,但是当收到电子邮件时,它们会显示“false”一词 我的控制器 public function sendmail() { $this->load->library('email'); $this->load->model('Email_mo

我有一个应用程序,其中我有一个wysiwyg编辑器来设计电子邮件并将其发送到数据库中的联系人,我有电子邮件功能,就像我使用发送到数据库联系人的输入表单进行测试一样,然而,我试图通过ajax将所见即所得编辑器中的内容传递给我的控制器,但是当收到电子邮件时,它们会显示“false”一词

我的控制器

public function sendmail() {


$this->load->library('email');
$this->load->model('Email_model');
$this->load->library('session');
$this->email->from($this->input->post('email'), $this->input-
>post('name'));
$this->email->to($this->Email_model->emailsend());
$this->email->subject('Hello This is an email');
$this->email->message($this->input->post('content'));

if ($this->email->send()){

   $this->load->view('header');
  $this->load->view('sentConfirm');
  $this->load->view('footer');

}else{
echo $this->email->print_debugger();
}
}
我的阿贾克斯

$('#sendEmail').click(function () {

$.ajax({
    type: 'POST',
    url: "<?=site_url("dashboard/sendmail"); ?>",
    data: {
    content: $("trumbowyg-demo").trumbowyg('html')
},
    dataType: 'json',
success: function(response){
console.log('Sent Successfully');
}
});
});
$('#发送电子邮件')。单击(函数(){
$.ajax({
键入:“POST”,
url:“”,
数据:{
内容:$(“trumbowyg演示”).trumbowyg('html')
},
数据类型:“json”,
成功:功能(响应){
log(“发送成功”);
}
});
});

我们建议使用phpmailer而不是codeigniter电子邮件助手

试试看;

ajax

$('#sendEmail').click(function () {

    $.ajax({
        type: 'POST',
        url: "<?=site_url("dashboard/sendmail"); ?>",
        data: {content: $("trumbowyg-demo").trumbowyg('html')},
        dataType: 'json',
        success: function(response){
            if(response.ok==1) {
                alert('sent');
            }else{
                alert('failed');
            }
        },
        error: function(response){
            alert('error');
        }
    });
});

您需要添加$mail->IsHTML(true);在$mail->message之前,因为所见即所得编辑器返回的内容是html@VishnuBhadoriya这将返回对未定义方法CI_Email::IsHTML()的调用
public function sendmail() {
        $configs = Array(
          'mailtype' => 'html'
          //see other config in https://www.codeigniter.com/user_guide/libraries/email.html#email-preferences
        );

        $this->load->library('email');
$this->email->initialize($configs);
        $this->load->model('Email_model');
        $this->load->library('session');
        $this->email->from($this->input->post('email'), $this->input->post('name'));
        $this->email->to($this->Email_model->emailsend());
        $this->email->subject('Hello This is an email');
        $this->email->message($this->input->post('content'));

        $result['ok'] = 0;
        if ($this->email->send()){
            $result["ok"]=1;
        }
        echo json_encode($result);
    }