dpo15099 2015-12-26 16:37
浏览 46
已采纳

为什么我的HTML / PHP表单回显PHP文件并在指定post时使用get? [重复]

This question already has an answer here:

I've been working on a website for my father for a while now and i have been getting frustrated with the contact form and order form. I'm only starting to learn HTML and i don't know a whole lot about it.

Here is what's happening: When i press the submit button, the whole PHP code will print onto the browser screen in plain text.

This is happening for both the contact form and order form, i will paste the contact form bellow.

                            <form id="contact-form" action="php/mail.php" method="POST">
                                <div class="control-group">
                                    <div class="controls">
                                        <input class="span12" type="text" id="name" name="name" placeholder="* Your name..." />
                                        <div class="error left-align" id="err-name">Please enter name.</div>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <input class="span12" type="email" name="email" id="email" placeholder="* Your email..." />
                                        <div class="error left-align" id="err-email">Please enter valid email adress.</div>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <textarea class="span12" name="comment" id="comment" placeholder="* Your query..."></textarea>
                                        <div class="error left-align" id="err-comment">Please enter your query.</div>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <div class="controls">
                                        <button id="send-mail" class="message-btn">Send message</button>
                                    </div>
                                </div>
                            </form>

Here is the PHP:

<?php
include 'functions.php';

if (!empty($_POST)){

$data['success'] = true;
$_POST  = multiDimensionalArrayMap('cleanEvilTags', $_POST);
$_POST  = multiDimensionalArrayMap('cleanData', $_POST);

$emailTo ="myemail@domain.com"; 

$emailSubject = "Test";

$name = $_POST["name"];
$email = $_POST["email"];
$comment = $_POST["comment"];
if($name == "")
$data['success'] = false;

if (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email)) 
$data['success'] = false;


if($comment == "")
$data['success'] = false;

if($data['success'] == true){

$message = "NAME: $name<br>
EMAIL: $email<br>
COMMENT: $comment";


$headers = "MIME-Version: 1.0" . "
"; 
$headers .= "Content-type:text/html; charset=utf-8" . "
"; 
$headers .= "From: <$emailFrom>" . "
";
mail($emailTo, $emailSubject, $message, $headers);

$data['success'] = true;
echo json_encode($data);
}
}

The email part is filled in with my email.

Just to recap, the whole php code in echoing to my browser in plain-text when i press the submit button.

I don't see anything wrong with this, please help...

</div>
  • 写回答

1条回答 默认 最新

  • doudou20080720 2015-12-26 16:44
    关注

    PHP code is printed when you post the form.

    It does mean you don't have php installed on your machine or your web server doesn't have php module enabled.

    Try to install apache or IIS or any other webserver + php and then run your contact form on localhost url.

    e.g. http://localhost/contactform.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化