我有這個PHP發送郵件的問題。PHP的郵件發送ajax
我有這種形式在index.php頁面:
<form action="">
<input placeholder="Name" class="form" id="name" type="text" required/>
<input placeholder="Email" class="form" id="mail" type="email" required />
<input placeholder="Object" class="form" id="object" type="text" required />
<textarea placeholder="Type here..." id="text" class="form"></textarea>
<input class="formBtn" type="submit" id="submit"/>
<input class="formBtn" type="reset" />
在index.php
<script>
$('#submit').click(function() {
var nameform = $('#name').val();
var mailform = $('#mail').val();
var objectform = $('#object').val();
var textform = $('#text').val();
var mailcomplete = 'Name='+nameform+'Mail='+mailform+'Object='+objectform+'Message='+textform;
$.ajax({
type: "POST",
url: 'php/mail.php',
data: mailcomplete,
success: function() {
alert("Mail send OK!");
}
});
});
的底部這個腳本,這在PHP/mail.php
<?php
$name = $_POST["nameform"];
$mail = $_POST["mailform"];
mail($mail, $name, "Hello!");
?>
但是不行......你能幫我嗎? TNK
按鈕有什麼錯誤?究竟發生了什麼? 看起來像點擊按鈕時刷新頁面,所以它不運行ajax代碼。 –