请不要说我对 php 不是很好,所以所有的帮助都将不胜感激。
无论如何,我有这个表格:
<form method="post" action="mail.php" id="contactform">
<div class="stage cf">
<input type="text" name="contactname" id="contactname" placeholder="Name" class="required" role="input" aria-required="true" />
</div>
<div class="stage cf">
<input type="text" name="email" id="useremail" placeholder="Email" class="required email" role="input" aria-required="true" />
</div>
<div class="stage cf">
<input type="text" name="subject" id="subject" placeholder="Subject" class="required" role="input" aria-required="true" />
</div>
<div class="stage cf">
<textarea rows="5" name="message" id="message" placeholder="Message" class="required" role="textbox" aria-required="true"></textarea>
</div>
<input type="submit" value="Send Message" name="submit" id="submitButton" title="SendMessage" />
<div id="response"></div>
</form>
发送表单时,我想在同一页面上显示一条死亡消息。此时的消息显示在另一页上。
我的这个mail.php
文件块发送邮件:
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'test@randommail.com'; //Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
$headers = "From: $email";
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
die("<span class='success'>Success! Your message has been sent.</span>");
这个 Ajax 应该可以解决问题:
submitHandler: function(form) {
$("#send").attr("value", "Sending...");
$(form).ajaxSubmit({
success: function(responseText, statusText, xhr, $form) {
$(form).slideUp("fast");
$("#response").html(responseText).hide().slideDown("fast");
}
});
return false;
}