我正在尝试这样做,当用户单击页面底部的联系按钮时,PHP 脚本将检查消息是否正确发送并根据状态显示面板。我已经实现了一个 CSS 类来显示一个面板,但这不起作用。
样本:
该脚本可以在 AdamGinther.com 上找到
http://jsfiddle.net/gintherthegreat/ZFkmt/
<div id="contactme">
<p>Whether you’re just stopping to say hi or you have an inquiry, I enjoy receiving messages. For all of those employers out there, I am searching far and wide for a summer internship.</p>
<br> <a href="https://www.facebook.com/whoisthecoolestpersonalive?ref=tn_tnmn">
<img src="images/facebook-512.png" height="50" width="50" alt="Facebook" target="_new">
</a>
<br>
<br>
<form action="contact.php" method="post">
<label name="firstName">Name:</label>
<input type="text" name="firstName">
<br>
<br>
<label name="email">E-mail Address:</label>
<input type="text" name="email">
<br>
<br>
<label name="message">Message:</label>
<textarea name="message" id="message"></textarea>
<br>
<br>
<input type="submit" value="Say Hello!" id="contactbutton">
</form>
<div id="panel">
<h1 id="output-inside"></h1>
<br>
<input type="button" alt="close" value="close" id="close-panel">
</div>
<?php $field_firstName=$ _POST[ 'firstName']; $field_email=$ _POST[ 'email']; $field_message=$ _POST[ 'message']; $mail_to='gintherthegreat@gmail.com' ; $subject='AdamGinther.com message from ' .$field_firstName; $body_message='From: ' .$field_firstName. "\n"; $body_message .='E-mail: ' .$field_email. "\n"; $body_message .='Message: ' .$field_message; $headers='From: ' .$field_email. "\r\n"; $headers .='Reply-To: ' .$field_email. "\r\n"; $mail_status=m ail($mail_to, $subject, $body_message, $headers); if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
$('#panel').show();
$('#output-inside').text('Thank you ' + firstName + ', I will get back to you as soon as I can.');
</script>
<?php } else { ?>
<script language="javascript" type="text/javascript">
$('#panel').show();
$('#output-inside').text('I am sorry ' + firstName + ', but there was a problem processing your request. I can be contacted by e-mail at GintherTheGreat@Gmail.com');
</script>
<?php } ?>