提交按钮下载PHP的,而不是运行它(Submit button is downloading the

2019-09-02 02:19发布

我试图让我的网站上的联系表格,但是当我按下提交,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 
}
?>

我找不到什么是错的!

Answer 1:

如果实际的PHP代码索里正在下载,你有你的Web服务器的一些配置问题,但我不会去到这里。

我建议你删除的邮件命令的@盈虽然,因为这surpresses你可能有错误。

一个错误的IE浏览器。 你surpressing是哟ü。不要把有$消息变量,考虑的事实,你的代码说:其实$email_from = $_POST['Message']; // required $email_from = $_POST['Message']; // required

除此之外:我建议你关于命名关于大/小写字符约定阅读起来。 它使调试代码也更容易一些。 尝试http://framework.zend.com/manual/1.12/en/coding-standard.naming-conventions.html对于初学者。

PS。 你实际上有$消息变量,但其空。



Answer 2:

我面临着同样的问题。 我WAMP的服务器上尝试此。 它工作得很好,当我键入URL: localhost/login.html和注册。 当我通过编辑器中打开它的问题就来了。 新的URL是localhost:66342/login.html

因此,所有我需要做的就是在原来的网址,而不是这种新的类型和它的工作。



Answer 3:

所有你需要的是一个Web服务器。
对于使用LAMP服务器,将文件移动到无功/ www / html等文件夹中的作品。
如果你不想要移动的文件,然后简单地开启在你的文件目录中的Web服务器。 (假设你的文件名为index.html / index.php文件中指定的以下命令的文件名,否则。)

php -S localohost:8080 <filename>

现在访问的http://本地主机:8080 / ,你是好去。



文章来源: Submit button is downloading the php instead of running it