【问题标题】:Issue with one page site contact form一页网站联系表的问题
【发布时间】:2013-06-22 21:31:08
【问题描述】:

我有一个带有联系表的单页投资组合,我一直在尝试解决这个问题,但没有成功。我不是 PHP 专家,所以我会尽力解释。基本上我所拥有的是我过去使用过的来自 word press 的联系人模板文件,但我想要做的是(如果可能的话)在我的投资组合中实现。我的主要问题是,当我在浏览器中预览我的网站时,它会显示表单上的 PHP 代码。

<?php
            if ($_SERVER['REQUEST_METHOD'] == "POST") {
                // Check fields for errors

                if (empty($_POST["txtName"])) {
                    $errors["txtName"] = "Please enter your name.";
                }

                if (empty($_POST["txtPhone"])) {
                    $errors["txtPhone"] = "Please enter your phone number.";
                }


                if (empty($_POST["txtEmail"])) {
                    $errors["txtEmail"] = "Please enter your email address.";
                } else {
                    if (!eregi('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$', stripslashes(trim($_POST["txtEmail"])))) {
                        $errors["txtEmail"] = "Please provide a valid email address.";
                    }

                }

                if (count($errors) < 1) {

                        $to = "test-email@gmail.com";
                        $subject = 'Bave Designs Contact';
                        $headers = "From:" . $_POST["txtEmail"] . "\r\n";
                        $headers .= "MIME-Version: 1.0\r\n";
                        $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
                        $message = '<html><body style="font-family:Arial, Helvetica, sans-serif; font-size:12px;">';
                        $message .= '<p><strong>Name:</strong> ' . $_POST["txtName"] . '<br />

                                    <strong>Phone:</strong> ' . $_POST["txtPhone"] . '<br />
                                    <strong>Email:</strong> ' . $_POST["txtEmail"] . '<br />

                                    <strong>Message:</strong><br />' . $_POST["txtComment"] . '</p>
                                    </body>
                                    </html>';
                        if ( !mail($to,$subject,$message,$headers) ) {

                            $errors["send"] = "There was a problem sending your message.  Please try again.";
                        }

                } 
            }
            <div id="contact-form">
                    <?php
                if (count($errors) > 0) {
                    echo '<ul style="color:red; padding:0 0 18px 22px;">';
                    foreach ($errors as $error) {
                        echo "<li>" . $error . "</li>";
                    }
                    echo "</ul>";
                }
                ?>
                <?php if ($_SERVER['REQUEST_METHOD'] == "POST" && count($errors) < 1) { ?>
            <p class="success-message"><?php _e('Thank you! Your message has been sent.'); ?></p>
            <?php } else { ?>

            <form id="contact1" method="post" action="#message" class="contact-form">
                <p><label for="txtName">Name</label>
                <input type="text" id="txtName" name="txtName" class="field" size="40" value="<?php echo $_POST['txtName'] ?>" /></p>

                <p><label for="txtPhone">Phone</label>
                <input type="text" id="txtPhone" name="txtPhone" class="field" size="40" value="<?php echo $_POST['txtPhone'] ?>" /></p>

                <p><label for="txtEmail">Email</label>
                <input type="text" id="txtEmail" name="txtEmail" class="field" size="40" value="<?php echo $_POST['txtEmail'] ?>" /></p>

                <p><label for="txtComment">Message</label>
                <textarea name="txtComment" id="txtComment" class="field" cols="40" rows="10"><?php echo $_POST['txtComment'] ?></textarea></p>

                <p><input type="submit" id="btnSubmit" name="btnSubmit" class="button" value="Submit" /></p>

            </form>
            <?php } ?>
        </div><!-- CONTACT FORM ENDS-->

我将wp_mail 函数切换为mail,我知道这是正确的。

任何帮助将不胜感激。

提前致谢。

【问题讨论】:

  • 并且文件有.php扩展名?
  • 如果你得到 php 代码,那么你的服务器是 miconfigurd,或者你(比如说)使用 .html 文件扩展名,而不是 .php。您还使用了古老且已被高度弃用的 ereg 函数,这是一个坏主意。
  • 你是在adminpage还是template文件中写上面的代码?
  • 不,它没有 .php 文件扩展名,-Marc B,你对我应该使用什么类型的函数或者更适合我想要实现的功能有什么建议吗? ,这是一个简单的联系表格,可以将信息发送到我的电子邮件帐户?

标签: php forms contact


【解决方案1】:

我的主要问题是,当我在浏览器中预览我的网站时,它会显示 表单上的 PHP 代码。

那么,如果我理解正确,您的 PHP 代码会显示在您的页面中吗?

如果是这种情况,我建议您尽快联系您的虚拟主机提供商,因为您的 Apache 配置似乎存在很大问题。

【讨论】:

  • 我相信这只是那个愚蠢的文件扩展名,.php 而不是 .html,还有一个未封闭的 .php 标签
猜你喜欢
  • 1970-01-01
  • 2016-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-13
  • 2014-12-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多