저는 codeigniter의 문의 양식을 통해 이메일을 보내기 위해 ajax를 사용하고 있습니다. 아약스 (JQuery와) 부분은 다음과 같습니다codeigniter 및 ajax : aborted request로 이메일 보내기
var dataString = 'nome=' + nome + '&msg=' + msg + '&email=' + email + '&secure=' + secure + '&mailto=' + mailto + '&ci_token=' + $.cookie("ci_csrfprotection_cookie");
$.ajax({
url: '<?php echo site_url();?>/contact/send',
type: 'POST',
data: dataString,
timeout: 1000,
dataType: "json",
success: function(msg){
if(msg.sent){
$('#feedback').html("<?php echo lang('email_sucesso'); ?>").delay(6000).hide('slow');
}
else{
$('#feedback').html("<?php echo lang('email_erro'); ?>").delay(6000).hide('slow');
}
botao.attr('disabled', false);
}
});
그리고 컨트롤러는 다음과 같습니다
public function send()
{
if ($this->input->post('secure') != 'siteform') {
echo lang('erro_no_js');
}else{
$this->load->library('email');
$nome = $this->input->post('nome');
$email = $this->input->post('email');
$msg = $this->input->post('msg');
$mailto = $this->input->post('mailto');
$secure = $this->input->post('secure');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.googlemail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = $this->settings['smtp_email'];
$config['smtp_pass'] = $this->settings['smtp_password'];
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$this->email->initialize($config);
$this->email->from($email, $nome);
$this->email->to($mailto);
$this->email->subject('Contacto do site');
$this->email->message($msg);
if ($this->email->send()){
echo json_encode(array("sent"=>TRUE));
}else{
echo json_encode(array("sent"=>FALSE));
}
}
}
이 실제로 올바르게 전자 메일을 보냅니다하지만 AJAX 호출이 중단됩니다 내가 다시 메시지가 없습니다.
그러나 내가 $this->email->send()
비트를 제거하면 응답이 올바르게 표시되지만 물론 이메일은 전송되지 않습니다.
무엇이 여기에 있습니까?
참고 : CSRF를 사용할 수 있으며 데이터베이스를 쿼리하는 다른 ajax 호출에서 제대로 작동합니다.
당신이 다시 무엇을 얻을 볼 방화범이 끌려와 아약스 요청을 확인 했습니까? – beerwin
@beerwin 예 요청이 중단되고 아무것도 반환하지 않지만 '$ this-> email-> send()'가 없으면 응답이 올바르게 반환됩니다. – fana
이 줄'if (msg.sent) {'바로 뒤에 console.log 또는 경고를 넣고 실제로이 코드를 얻는 지보십시오. – Catfish