試圖在Codeigniter中設置AJAX聯繫表單。這是我第一次使用CI。Codeigniter Mail - 我有它的工作,現在不是。告訴我爲什麼?
我有它的工作,現在它壞了,我不知道爲什麼。
這裏是代碼..
的JS
$.ajax({
type:'POST',
url: post_url,
data: post_data,
beforeSend:function(){
alert(this.data); <<< This is alerting the correct form data to me
},
success:function(msg){
$($form).fadeOut(500, function(){
var msg = '<div class="messageSent"><p>'+ msg +'</p></div>';
$form.html(msg).fadeIn(); <<< This is returning undefined
});
}
});
..和PHP ...
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Email extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->library('email');
}
public function index(){
$emailFromName = $this->input->post('name', TRUE);
$emailFromAddress = html_entity_decode($this->input->post('email', TRUE));
$emailFromMessage = "Email from the Brewer's website\n";
$emailFromMessage .= "==============================\n";
$emailFromMessage .= "From: " + $emailFromName + "\n";
$emailFromMessage .= "==============================\n";
$emailFromMessage .= "Respond Email; " + $emailFromAddress +"\n";
$emailFromMessage .= "==============================\n";
$emailFromMessage .= $this->input->post('message', TRUE);
$this->email->from($emailFromName);
$this->email->to('[email protected]');
$this->email->subject('Message from the website.');
$this->email->message($emailFromMessage);
$this->email->send();
echo $this->email->print_debugger(); // echoes undefined
// echo($emailFromName); // also echoes undefined
}
}
?>
,我認爲這個問題必須在PHP ..它只是似乎沒有讀取任何發佈的變量。我甚至不能echo $ this-> input-> post('name'); (雖然我有它的工作!)
..所以我做錯了什麼?
注 - 我把html_entity_decode放在那裏,因爲我注意到電子郵件地址變成了「address%40gmail.com」......所以它看起來是個好主意。有必要嗎?
好了,一個顯而易見的問題:因爲它的工作你有什麼改變? –
你是否自動加載電子郵件庫?另外,你是否通過控制檯驗證了ajax部分是否實際發送了正確的數據並且不會拋出錯誤?另外,如果是這樣,你是否最近改變主機或東西,或許是302清除你的發佈數據? – Rooster
@DanielHilgarth Ha。粗略地57到83.5個小東西。這些都不應該影響郵件! –