提交此表单后,我会收到一封电子邮件,其中所有值均为空白,请帮助我。
这是我的 html 文件,我在其中接受姓名、电子邮件和消息作为输入。
<form id="form" method="post" action="contact.php" >
<fieldset>
<label><input type="text" value="Name" onBlur="if(this.value=='') this.value='Name'" onFocus="if(this.value =='Name' ) this.value=''"></label>
<label><input type="text" value="Email" onBlur="if(this.value=='') this.value='Email'" onFocus="if(this.value =='Email' ) this.value=''"></label>
<label><textarea onBlur="if(this.value==''){this.value='Message'}" onFocus="if(this.value=='Message'){this.value=''}">Message</textarea></label><br>
<<a href="#" class="button" onClick="document.getElementById('form').submit()">Send</a></div>
</fieldset>
</form>
.php 文件:
在 php 文件中,我想通过电子邮件发送 id jay44556677@gmail.com 上的所有详细信息。
<?php
$field_name = $_POST['Name'];
$field_email = $_POST['Email'];
$field_message = $_POST['Message'];
$mail_to = 'jay44556677@gmail.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\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 = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contacts.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please try again.');
window.location = 'contacts.html';
</script>
<?php
}
?>
我该如何解决?