我有一个应用程序,我有一个所见即所得的编辑器来设计电子邮件并将其发送给数据库中的联系人,我有电子邮件功能,就像我测试时它发送到我的数据库联系人的输入表单一样,但是我正在尝试将所见即所得编辑器中的内容通过 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
$('#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);
}
我们建议使用phpmailer而不是codeigniter电子邮件助手。
试试吧 ;https://github.com/ivantcholakov/codeigniter-phpmailer