現在我的網站打開了,用戶可以選擇他們想要訂購的東西。當他們想要提交訂單時,我只想發送一封電子郵件,但電子郵件未通過,我的頁面剛剛重新啓動。單擊按鈕時AJAX不會被調用?
的JavaScript/AJAX:
<script type="text/javascript">
$(document).ready(
function() {
$('#wholesaleOrderForm').submit(
function() {
if (validateForm()) {
$.post("wholesale_form.php",
$('#wholesaleOrderForm').serialize(),
function(response) {
alert('response = ' + response);
if (response == "success") {
$('#ajax-msg').html("Thanks for subscribing!");
$('#ajax-msg').style.color = "green";
$('#ajax-msg').hide(5000);
} else {
$('#ajax-msg').html("Sorry, there is some error. Please try again.");
$('#ajax-msg').style.color = "red";
$('#ajax-msg').hide(5000);
}
}
);
// prevent postback
return false;
} else {
return false;
}
}
);
}
);
</script>
PHP代碼:
<?php
$to = "[email protected]";
$subject = 'hello';
$message = "Hello!!";
$headers = 'From: [email protected]_EMAIL.com';
mail($to, $subject, $message, $headers);
?>
定義'這不是working' –
更新問題 –
檢查'郵件的返回值',如果它是'true',那麼郵件服務器已經接受了郵件,所以這個問題不在PHP部分。 –