【问题标题】:CodeIgniter - Sending content to controller via ajax and through code igniter email libraryCodeIgniter - 通过 ajax 和代码点火器电子邮件库向控制器发送内容
【发布时间】:2018-08-25 10:52:58
【问题描述】:

我有一个应用程序,我有一个所见即所得的编辑器来设计电子邮件并将它们发送给数据库中的联系人,当我使用它发送给我的数据库联系人的输入表单进行测试时,我的电子邮件功能可以正常工作,但是我正在尝试通过 ajax 将所见即所得编辑器中的内容传递给我的控制器,但是当收到电子邮件时,它们会显示“假”字样..

我的控制器

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');
}
});
});

【问题讨论】:

  • 你需要添加 $mail->IsHTML(true);在 $mail->message 之前,因为所见即所得编辑器返回的内容是 html
  • @VishnuBhadoriya 这将返回对未定义方法 CI_Email::IsHTML() 的调用

标签: php mysql codeigniter email


【解决方案1】:

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');
        }
    });
});

你的控制器

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);
    }

【讨论】:

    【解决方案2】:

    我们推荐使用 phpmailer 而不是 codeigniter 电子邮件助手。

    试试看; https://github.com/ivantcholakov/codeigniter-phpmailer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-06
      相关资源
      最近更新 更多