我想發送電子郵件使用jQuery和PHP。發送電子郵件從PHP和jQuery
我的HTML代碼
<form id="contactform">
<table border="0" cellpadding="0" cellspacing="0" width="186">
<tbody>
<tr>
<td bgcolor="#2A677E" width="25"> </td>
<td bgcolor="#2A677E" width="161"> </td>
</tr>
<tr>
<td bgcolor="#2A677E"> </td>
<td bgcolor="#2A677E"><img src="images/icon-email.jpg" alt="" align="left" height="17" hspace="2" width="27"><span class="text-white">Email this page</span></td>
</tr>
<tr>
<td bgcolor="#2A677E"> </td>
<td bgcolor="#2A677E">
<input name="email" onFocus="this.value=''" onMouseOver="window.status='Enter email address here and tell a friend about this site...'; return true" onMouseOut="window.status='';return true" size="22" type="text" class="button required email">
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tbody>
<tr>
<td align="right" height="30"><input class="button-dark" onMouseOver="window.status='Click to send an email (with this page address) to a friend! Enter email address above...'; return true" onMouseOut="window.status='';return true" value="Send" type="submit">
</td>
<div class="saving" style="background-color:#D1F4DA;border:1px solid #017F1F;display:none;width:175px; font-size:12px; padding:5px;text-align:center; margin-left:-25px; margin-top:0px; position:absolute;"><img src="validate/ajax-loader.gif"/> Please Wait Processing Request </div>
<div class="success" style="background-color:#D1F4DA;border:1px solid #017F1F;display:none;width:175px; font-size:12px;padding:5px;text-align:center; margin-left:-25px; margin-top:0px; position:absolute;"> <img src="validate/validYes.png"/> Message Sent.<br />
Thanks.</div>
<div class="nosuccess" style="background-color:#ffebe8;border:1px solid #dd3c10;display:none;width:175px; font-size:12px;padding:5px;text-align:center; margin-left:-25px; margin-top:0px; position:absolute;"> <img src="validate/failed.png"/> Error Sending Email. </div>
</tr>
</tbody>
</table>
</form>
我有以下的jQuery代碼。
<script src="validate/jquery.js" type="text/javascript"></script>
<script id="demo" type="text/javascript">
$(document).ready(function() {
var validator = $("#contactform").validate({
submitHandler: function() {
$('div.sending').fadeIn('slow');
var a = <?php echo $_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]; ?>;
var email = $('#email').attr('value');
$.ajax({
type: "POST",
url: "send_page_friend.php",
data: "a="+ a +"&email="+ email,
success: function(html){
if (html==1){
$('div.saving').hide();
$('div.success').fadeIn();
setTimeout(function() {
$('div.success').fadeOut('slow');
}, 3000);
}
if (html==2){
$('div.saving').hide();
$('div.nosuccess').fadeIn();
setTimeout(function() {
$('div.nosuccess').fadeOut('slow');
}, 3000);
}
}
});
}
});
});
</script>
,但我得到的錯誤是,當我按下提交按鈕,我去同一個頁面的查詢字符串像/?email=....
它不是調用一個PHP頁面,也沒有隱瞞股利。
感謝
它工作謝謝 – air 2012-07-20 21:19:59