Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 递交联络表格_Php_Forms_Submission - Fatal编程技术网

Php 递交联络表格

Php 递交联络表格,php,forms,submission,Php,Forms,Submission,我是php新手-我正在尝试使用提供的模板代码提交一个简单的联系人表单。我得到以下错误报告: 致命错误:未捕获错误:函数名必须是第15行/home/u512372001/domains/thestripedphoenix.com/public_html/assets/php/mail.php:15堆栈跟踪:#0{main}抛出/home/u512372001/domains/thestripedphoenix.com/public_html/assets/php/mail.php中的字符串 php

我是php新手-我正在尝试使用提供的模板代码提交一个简单的联系人表单。我得到以下错误报告:

致命错误:未捕获错误:函数名必须是第15行/home/u512372001/domains/thestripedphoenix.com/public_html/assets/php/mail.php:15堆栈跟踪:#0{main}抛出/home/u512372001/domains/thestripedphoenix.com/public_html/assets/php/mail.php中的字符串

php出了什么问题

以下是HTML表单代码:


我想要一个。
标志
网站
抛光文件
宣传材料
低
正常的
高

本网站受reCAPTCHA和Google的保护
和
申请

表单提交的php代码:

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);



if(isset($_POST['submit'])) {
$to = "mymail@gmail.com";
$subject = "Subject Line";

        # Sender Data
        $name = str_replace(array("\r","\n"),array(" "," ") , strip_tags(trim($_POST["name"])));
        $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
        $category = $_POST(["category"]);
        $priority = $_POST(["priority"]);
        $message = trim($_POST["message"]);

        if ( empty($name) OR !filter_var($email, FILTER_VALIDATE_EMAIL) OR empty($message) OR empty($category)) {
            # Set a 400 (bad request) response code and exit.
            http_response_code(400);
            echo '<p class="alert alert-warning">Please complete the form and try again.</p>';
            exit;
        }

            # Mail Content
            $content = "Name: $name\r\n";
            $content .= "Email: $email\n\n";
            $content .= "I want a: $category\n\n";
            $content .= "Priority: $priority\n\n";
            $content .= "Message: $message\n\n";


            # Send the email.
            mail($to, $subject, $content);
            if ($success) {
                # Set a 200 (okay) response code.
                http_response_code(200);
                echo '<p class="alert alert-success">Thank You! Your message has been sent.</p>';
            } else {
                # Set a 500 (internal server error) response code.
                http_response_code(500);
                echo '<p class="alert alert-warning">Oops! Something went wrong, we couldnt send your message.</p>';
            }


    } else {
        # Not a POST request, set a 403 (forbidden) response code.
        http_response_code(403);
        echo '<p class="alert alert-warning">There was a problem with your submission, please try again.</p>';
    }



?>


从php表单中,如果用户没有完全填写表单,则会出现验证错误消息。一旦提交了所有必需的信息,该消息应转到我的电子邮件

如果您需要进一步的澄清,请告诉我。谢谢你的帮助

您的代码有语法错误 在这里:

在这里:

        echo '<p class="alert alert-warning">Oops! Something went wrong, we couldnt send your message.</p>';
    }
} // => closing bracket not matching anything

在运行代码之前,使用类似IDE的工具还可以帮助您设置格式和显示错误。

错误位于mail.php文件的第15行和第16行:

您的代码:

$category = $_POST(["category"]);
$priority = $_POST(["priority"]);
更新Coce:

$category = $_POST["category"];
$priority = $_POST["priority"];
只需删除括号“(“,”)”

我在form.php文件中为您提供了一个建议: 使用按钮而不是像这样输入:

<button type="submit" name="submit">Submit
提交

您可以分享错误消息吗?这是错误:致命错误:未捕获错误:函数名必须是/home/u512372001/domains/thestripedphoenix.com/public_html/assets/php/mail.php中的字符串:15堆栈跟踪:#0{main}在第15行的/home/u512372001/domains/thestripedphoenix.com/public_html/assets/php/mail.php中抛出,您不能在运行时使用这些函数修改错误报告设置,只要语法错误首先阻止整个程序运行。根据您的评论,我已将其修复。但是,当我测试提交时,它返回一个“您的提交有问题,请再试一次”,这是响应代码中的错误403。@user129533
$\u POST['submit']
未设置,因此您的代码将始终返回403错误。将`name=“submit”`添加到您的提交按钮。@SvenMich当我应用您在HTML中建议的内容时,它仍然会返回403错误。php表单似乎可以运行,但提交后速度会非常慢,我会得到错误500。有什么建议吗?另外,如何在响应代码之后重定向页面?
$category = $_POST["category"];
$priority = $_POST["priority"];
<button type="submit" name="submit">Submit