Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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_Html_Action_Form Submit_Contact Form - Fatal编程技术网

提交按钮下载PHP文件,而不是将数据发送到联系人表单中的电子邮件

提交按钮下载PHP文件,而不是将数据发送到联系人表单中的电子邮件,php,html,action,form-submit,contact-form,Php,Html,Action,Form Submit,Contact Form,我正试图为我的网站制作一个联系表单,但当我按submit时,php文件被下载而不是运行。我用的是铬。我认为这是一个语法错误,但我在删除、添加和填充方面做得很糟糕,即使没有语法错误,它仍然下载文件而不是运行它,是的……它是php文件的确切名称 Html代码 <div class="form1" id="form" data-aos="fade-down" data-aos-once="true" data-aos

我正试图为我的网站制作一个联系表单,但当我按submit时,php文件被下载而不是运行。我用的是铬。我认为这是一个语法错误,但我在删除、添加和填充方面做得很糟糕,即使没有语法错误,它仍然下载文件而不是运行它,是的……它是php文件的确切名称

Html代码

<div class="form1" id="form" data-aos="fade-down" data-aos-once="true" data-aos-delay="200">
        <div class="row">
            <h2>We're happy to hear from you !</h2>
        </div>
        <form class="form" method="POST" action="form.php">
            <div class="contact-us">
                <h2>Contact Us !</h2>
            </div><hr>
            <div class="parent">
                <div class = "Name">
                    <label for = "fname">First Name:</label>
                    <input type = "text" maxlength="15" name = "fname"   placeholder="First name" required>
                </div>
                <div class = "Name">
                    <label for = "lname">Last Name:</label>
                    <input type = "text" maxlength="20" name = "lname"  placeholder="Second name" required>
                </div>
            </div>
                
            <div class = "email">
                <label for = "email">Email:<br></label>
                <input type = "email" minlength="8" name = "email"  placeholder="Your email" required>
            </div>
            
            <p class = "comment">
                <label for="message">Comments:<br></label>
                <textarea id="message" name="message" cols="10" rows="5" placeholder="Your Message"></textarea>
            </p>
            <div class="submit">
                <input  type="submit" class="submit-btn"  value="Send Us"  >
            </div>
        </form>
<?php
    if(isset($_POST['submit']))
    {
        $fname = $_POST['fname'];// Get fName value from HTML Form
        $lname = $_POST['lname']; // Get lName value from HTML Form
        $email_id = $_POST['email']; // Get Email Value
        $msg = $_POST['message']; // Get Message Value
        $to = "...@gmail.com"; // You can change here your Email
        $subject = "'$name' has been sent a mail"; // This is your subject
         
        // HTML Message Starts here
        $message ="
        <html>
            <body>
                <table style='width:600px;'>
                    <tbody>
                        <tr>
                            <td style='width:150px'><strong>FName: </strong></td>
                            <td style='width:400px'>$fname</td>
                        </tr>
                        <tr>
                            <td style='width:150px'><strong>LName: </strong></td>
                            <td style='width:400px'>$lname</td>
                        </tr>
                        <tr>
                            <td style='width:150px'><strong>Email ID: </strong></td>
                            <td style='width:400px'>$email_id</td>
                        </tr>
                        <tr>
                            <td style='width:150px'><strong>Message: </strong></td>
                            <td style='width:400px'>$msg</td>
                        </tr>
                    </tbody>
                </table>
            </body>
        </html>
        ";
        // HTML Message Ends here
         
        // Always set content-type when sending HTML email
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
 
        // More headers
        $headers .= 'From: Admin <...@gmail.com>' . "\r\n"; // Give an email id on which you want get a reply. User will get a mail from this email id
         
        if(mail($to,$subject,$message,$headers)){
            // Message if mail has been sent
            echo "<script>
                    alert('Mail has been sent Successfully.');
                </script>";
        }
 
        else{
            // Message if mail has been not sent
            echo "<script>
                    alert('EMAIL FAILED');
                </script>";
        }
    }
?>

我们很高兴收到你的来信!
联系我们!

名字: 姓氏: 电子邮件:

评论:

php代码

<div class="form1" id="form" data-aos="fade-down" data-aos-once="true" data-aos-delay="200">
        <div class="row">
            <h2>We're happy to hear from you !</h2>
        </div>
        <form class="form" method="POST" action="form.php">
            <div class="contact-us">
                <h2>Contact Us !</h2>
            </div><hr>
            <div class="parent">
                <div class = "Name">
                    <label for = "fname">First Name:</label>
                    <input type = "text" maxlength="15" name = "fname"   placeholder="First name" required>
                </div>
                <div class = "Name">
                    <label for = "lname">Last Name:</label>
                    <input type = "text" maxlength="20" name = "lname"  placeholder="Second name" required>
                </div>
            </div>
                
            <div class = "email">
                <label for = "email">Email:<br></label>
                <input type = "email" minlength="8" name = "email"  placeholder="Your email" required>
            </div>
            
            <p class = "comment">
                <label for="message">Comments:<br></label>
                <textarea id="message" name="message" cols="10" rows="5" placeholder="Your Message"></textarea>
            </p>
            <div class="submit">
                <input  type="submit" class="submit-btn"  value="Send Us"  >
            </div>
        </form>
<?php
    if(isset($_POST['submit']))
    {
        $fname = $_POST['fname'];// Get fName value from HTML Form
        $lname = $_POST['lname']; // Get lName value from HTML Form
        $email_id = $_POST['email']; // Get Email Value
        $msg = $_POST['message']; // Get Message Value
        $to = "...@gmail.com"; // You can change here your Email
        $subject = "'$name' has been sent a mail"; // This is your subject
         
        // HTML Message Starts here
        $message ="
        <html>
            <body>
                <table style='width:600px;'>
                    <tbody>
                        <tr>
                            <td style='width:150px'><strong>FName: </strong></td>
                            <td style='width:400px'>$fname</td>
                        </tr>
                        <tr>
                            <td style='width:150px'><strong>LName: </strong></td>
                            <td style='width:400px'>$lname</td>
                        </tr>
                        <tr>
                            <td style='width:150px'><strong>Email ID: </strong></td>
                            <td style='width:400px'>$email_id</td>
                        </tr>
                        <tr>
                            <td style='width:150px'><strong>Message: </strong></td>
                            <td style='width:400px'>$msg</td>
                        </tr>
                    </tbody>
                </table>
            </body>
        </html>
        ";
        // HTML Message Ends here
         
        // Always set content-type when sending HTML email
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
 
        // More headers
        $headers .= 'From: Admin <...@gmail.com>' . "\r\n"; // Give an email id on which you want get a reply. User will get a mail from this email id
         
        if(mail($to,$subject,$message,$headers)){
            // Message if mail has been sent
            echo "<script>
                    alert('Mail has been sent Successfully.');
                </script>";
        }
 
        else{
            // Message if mail has been not sent
            echo "<script>
                    alert('EMAIL FAILED');
                </script>";
        }
    }
?>

如果您可以将其添加到您的
apache配置文件中

AddType application/x-httpd-php .php 
那会解决你的问题

如何-


还要确保在wamp或xamp等服务器环境中运行代码。如果您正在脱机工作。

您的Web服务器未配置为执行PHP文件;这与您发布的代码无关,但这是由于您所设置的任何Web服务器中缺少配置造成的。欢迎使用堆栈溢出!请访问,带上,查看和,搜索有关SO的主题;如果遇到问题,请发布您的尝试,并使用
[]
代码段编辑器记录输入和预期输出。您还需要在提交按钮中添加name=“submit”,因为您正在检查是否设置了$\u post['submit']。您正在测试name=“submit”-以表单“submit”命名任何内容都不是一个好主意如果您计划使用JavaScript提交。您仍然需要命名submit按钮并测试它是否已设置-因此
if(isset($\u POST['submit-btn'))