當我測試它,我得到一個彈出稱其提交,但我也從阿賈克斯部分得到一個消息,說有一個錯誤,即使所有的內容通過電子郵件來我成功。聯繫表不工作[PHP/AJAX]
我覺得有一個問題是,有從相應的PHP和AJAX的未來都兩個不同的提交郵件。 PHP需要嗎?將不勝感激的幫助。
UPDATE:「錯誤什麼不對」
該錯誤消息我得到的是來自阿賈克斯後提交的錯誤響應,說我也會彈出一個消息,說它是正確提交的,並且是來自PHP的回顯。
UPDATE* * 真人版:http://pieceofmedesigns.com/test/contact.html
這裏是AJAX:
$(function(){
$("#Submit").click(function(){
$.ajax({type:'POST', url: './php/mailer.php', data:$('#frmContact').serialize(), success: function(response) {
$("#spanMessage").html('Please Wait...');
if(parseInt(response)>1)
{
$("#spanMessage").html('<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button><strong>Well done!</strong> Your message has been sent.</div>');
}
else{
alert(response);
$("#spanMessage").html('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button><strong>Error! </strong> Somthing Wrong</div>');
}
}});
});
這裏是PHP梅勒:
<?php session_start();
if(isset($_POST['Submit'])) {
$youremail = '[email protected]';
$fromsubject = 'Test Email';
$txtName = $_POST['txtName'];
$txtEmail = $_POST['txtEmail'];
$txtSubject = $_POST['txtSubject'];
$txtText = $_POST['txtText'];
$to = $youremail;
$mailsubject = 'Masage recived from'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is '.$txtName.'
E-mail: '.$txtEmail'
Message:
'.$txtText.'
|---------END MESSAGE----------|';
echo "Thank you fo your feedback. I will contact you shortly if needed.<br/>Go to <a href='/index.php'>Home Page</a>";
mail($to, $subject, $body);
} else {
echo "You must write a message. </br> Please go to <a href='/contact.php'>Contact Page</a>";
}
?>
下面的形式:
<form action="" method="post" id="frmContact">
<h5>Whats your Name?</h5>
<input name="txtName" type="text" class="txbx" value="Name" /><br />
<h5>Whats your Email?</h5>
<input name="txtEmail" type="text" class="txbx" value="Email" /><br />
<h5>Email Subject?</h5>
<input name="txtSubject" type="text" class="txbx" value="Subject" /><br />
<div class="erabox">
<h5>Message to us</h5>
<textarea name="txtText" cols="" rows="" class="txbx era" value="Message" ></textarea> <br />
<input name="" type="button" class="sendbtn" value="Send Message" align="left" id="btnSend"/>
</form>
我沒有在你的形式看是「提交」 – sanj 2013-02-22 09:27:53
可以請你在你的問題中添加確切的錯誤信息?謝謝 – 2013-02-22 09:30:03
您也可以將按鈕放在窗體外面。通過這個,你肯定不會有表格提交。 – Perry 2013-02-22 09:30:04