我正在尝试为我的网站制作联系表格,但是当我按下提交时,php 文件被下载而不是被运行。我正在使用 chrome,但我认为这无关紧要是的...它是 php 文件的确切名称 (SendEmail.php)
HTML
<form name="contactform" method="post" action="SendEmail.php">
<div class="ContactHeaders">Name:</div>
<input type="text" name="Name" class="ContactBoxes"/>
<div class="ContactHeaders">Email:</div>
<input type="text" name="Email" class="ContactBoxes"/>
<div class="ContactHeaders">Message:</div>
<div style="width:100%">
<textarea name="Message" maxlength="1000"></textarea>
</div>
<div style="width: 100%">
<input type="submit" class="Submitbtn" value="Submit">
</div>
</form>
PHP
if(isset($_POST['Email'])) {
$email_to = "email@domain.com";
$email_subject = "Website Contact";
function died($error) {
echo "We are very sorry, but there were error(s) found with the form you submitted.";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['Name']) ||
!isset($_POST['Email']) ||
!isset($_POST['Message'])) {
died('Sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['Name']; // required
$last_name = $_POST['Email']; // required
$email_from = $_POST['Message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$Email)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$Name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($Message) < 10) {
$error_message .= 'The message you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$Name .= clean_string($Name)."\n";
$Email .= clean_string($Email)."\n";
$Message .= clean_string($Message)."\n";
//email headers
$headers = 'From: '.$Email."\r\n".
'Reply-To: '.$Email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $Message, $headers);
?>
Thank you for contacting me. I will be in touch with you very soon.
<?php
}
?>
我找不到什么问题!!!