我有一个问题,我无法找到解决方案。我正在为我的网站创建简单的联系表单,当我按提交时,而不是运行php文件它显示代码。我试过几个PHP不同的脚本,每次都会发生同样的问题。这是我的HTML和PHP。 image
<form id="myform" name="myform" action="send_contact.php" method="post">
<label>Name</label>
<input type="text" name="name" id="name" />
<label>E-mail</label>
<input type="text" name="email" id="email" />
<label>Phone</label>
<input type="text" name="phone" id="phone" />
<label>Message</label>
<textarea name="message" rows="5" cols="60"></textarea>
<button name="send" type="submit">send</button>
<button name="reset" type="reset">reset</button>
<div class="spacer"></div>
</form>
.PHP
<?php
$headersep = "\r\n";
$header = "From: $name <$email>" . $headersep . "Reply-To: $name <$email> . $headersep";
$email = $_POST['email'];
$subject="Your subject here";
$phone = $_POST['phone'];
$message = "From: $name\n\nMessage: $message\n\nEmail: $email\n\nTelephone: $phone";
$to ='mymail@gmail.com';
if (!empty ($_POST['email']) && ($_POST['message'])) {
mail($to, $subject, $message, $header);
echo "Thank you $name, your message has been received.";
exit;
}
if ( (empty ($_POST['email'])) && (empty ($_POST['message'])) ) {
echo "ERROR, you did not fill in the <b>Email</b> and the <b>message</b> body.";
exit;
}
elseif (empty ($_POST['email'])) {
echo "ERROR, you did not fill in your Email address.";
exit;
}
elseif (empty ($_POST['message'])) {
echo "ERROR, you did not fill in the message body.";
exit;
}
?>