gpt4 book ai didi

php - CodeIgniter - 通过 ajax 和代码点火器电子邮件库将内容发送到 Controller

转载 作者:行者123 更新时间:2023-11-29 02:42:05 26 4
gpt4 key购买 nike

我有一个应用程序,我有一个所见即所得的编辑器来设计电子邮件并将它们发送给数据库中的联系人,我有电子邮件功能,当我测试它发送到我的数据库联系人的输入表单时,但是我正在尝试通过 ajax 将所见即所得编辑器中的内容传递给我的 Controller ,但是当收到电子邮件时,它们会显示“false”这个词。

我的 Controller

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

我的 Ajax

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

你的 Controller

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

关于php - CodeIgniter - 通过 ajax 和代码点火器电子邮件库将内容发送到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49319602/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com