提交按钮正在下载php而不是运行它 [英] Submit button is downloading the php instead of running it

查看:64
本文介绍了提交按钮正在下载php而不是运行它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的网站制作联系表单,但是当我按Submit时,将下载php文件而不是运行它。
我正在使用chrome,但认为这没关系
我认为存在语法错误,但我一直在删除,添加和填充内容,即使没有语法错误,它仍然会下载该文件而不是运行它
而且,是的...它是php文件的确切名称(SendEmail.php)

I'm trying to make a contact form for my website but when I press submit, the php file is downloaded instead of being ran. I am using chrome but don't think that should matter I think there's a syntax error but I've messed around with removing, adding and stuff and even when there is no syntax errors, it still downloads the file rather than runs it And, yes...it is the exact name of the php file (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 
}
?>

我找不到问题所在!!!

I can't find what's wrong!!!

推荐答案

如果正在下载实际的php源代码,则您的网络服务器上存在一些配置问题,但是我不会

If the actual php soure code is being downloaded, you have some configuration issues on your webserver, but I won't go into that here.

我确实建议您删除mail命令的@ infront,因为这会掩盖您可能遇到的错误。

I do suggest you remove the @ infront of the mail command though, since that surpresses errors you might be having.

错误之一。考虑到您的代码说: $ email_from = $ _POST [’Message’],您感到惊讶的是,您没有$ Message变量。 //必需

One of the errors ie. you are surpressing is the fact that yo u dont' have a $Message variable, considering the fact that your code says: $email_from = $_POST['Message']; // required.

除此之外:我建议您阅读有关大写/小写字符的命名约定。它使调试代码相当容易。尝试 http://framework.zend.com/manual/ 1.12 / zh-CN / coding-standard.naming-conventions.html (对于初学者)。

Aside from that: I suggest you read up about naming conventions concerning upper/lower case characters. It makes debugging code quite a bit easier. Try http://framework.zend.com/manual/1.12/en/coding-standard.naming-conventions.html for starters.

PS。实际上,您确实有一个$ Message变量,但是它为空。

PS. You do actually have a $Message variable, but its empty.

这篇关于提交按钮正在下载php而不是运行它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆