表单发送按钮php不工作

表单发送按钮php不工作,php,html,forms,Php,Html,Forms,我有一个简单的表格: <form action="send_form_email.php" method="post" enctype="text/plain"> <input type="text" name="first_name" placeholder="NAME:" size="100" class="grey-bg"/> <input type="text" name="last_name" placeholder="E-MAIL:" s

我有一个简单的表格:

<form action="send_form_email.php" method="post" enctype="text/plain">
    <input type="text" name="first_name" placeholder="NAME:" size="100" class="grey-bg"/>
    <input type="text" name="last_name" placeholder="E-MAIL:" size="100" class="grey-bg"/>
    <br />
    <br />
    <textarea type="text" name="message" rows="20" cols="201" placeholder="MESSAGE:" size="162"></textarea>
    <br />
    <div>
        <input id="contact-send-btn" type="submit" value="Send">
    </div>
</form>




这是php文件:

<?php

if(isset($_POST['email'])) {



    // EDIT THE 2 LINES BELOW AS REQUIRED

    $email_to = "xxxxxxxx";

    $email_subject = "Hello";





    function died($error) {

        // your error code can go here

        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['first_name']) ||

        !isset($_POST['last_name']) ||

        !isset($_POST['message']) ||

        died('We are sorry, but there appears to be a problem with the form you submitted.');       

    }



    $first_name = $_POST['first_name']; // required

    $last_name = $_POST['last_name']; // required

    $message = $_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_from)) {

    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';

  }

    $string_exp = "/^[A-Za-z .'-]+$/";

  if(!preg_match($string_exp,$first_name)) {

    $error_message .= 'The First Name you entered does not appear to be valid.<br />';

  }

  if(!preg_match($string_exp,$last_name)) {

    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';

  }

  if(strlen($message) < 2) {

    $error_message .= 'The Comments you entered do not appear to be valid.<br />';

  }

  if(strlen($error_message) > 0) {

    died($error_message);

  }

    $email_message = "Form details below.\n\n";



    function clean_string($string) {

      $bad = array("content-type","bcc:","to:","cc:","href");

      return str_replace($bad,"",$string);

    }



    $email_message .= "First Name: ".clean_string($first_name)."\n";

    $email_message .= "Last Name: ".clean_string($last_name)."\n";

    $email_message .= "Message: ".clean_string($email_from)."\n";



// create email headers

$headers = 'From: '.$email_from."\r\n".

'Reply-To: '.$email_from."\r\n" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);  

?>



<!-- include your own success html here -->



Thank you for contacting us. We will be in touch with you very soon.



<?php

}

?>

您没有将
名称
属性添加到提交按钮

改变

<input id="contact-send-btn" type="submit" value="Send">

致:


过帐表单时,只有名为
的元素才能过帐

在您的例子中,submit按钮没有name属性,所以它没有被发布


因此,如果

看起来您没有安装apache、php,那么它不会进入
,这就是您看到.php文件内容的原因。如果您在Windows上,请在Linux上安装XAMPP。希望这能帮助你解决一些问题

编码类型 PHP不支持纯文本编码的表单数据删除该属性(并使用默认编码类型)

另见:

使用文本/普通格式的有效载荷旨在为人类可读。计算机无法可靠地解释它们,因为格式不明确(例如,无法区分值中的文字换行和值末尾的换行)

提交测试 你说的
if(设置($_POST['email']){

…但是您没有任何带有
name=“email”
的字段。请测试您实际拥有的字段是否存在*

在浏览器中打开PHP 这句话有点模棱两可:

它只是在浏览器中打开php文件

如果您的意思是浏览器显示PHP源代码,请参见以下问题:

旁白
placeholder=“NAME:”


这无法匹配许多完全有效的电子邮件地址(例如
@
前面部分中带有
+
的电子邮件地址,或者来自
.museum
顶级域的电子邮件地址).

Open告诉你看到了什么没有改变任何东西?你的系统中可能没有安装PHP Apache,这就是为什么你看到.PHP文件的内容从哪里
$email\u from
来的??这个
if(isset($\u POST['email')){…}
不会发生,错误报告会给您带来一些关于未定义索引电子邮件通知的信息。我这样做了,但仍然没有做?我相信他们使用“电子邮件”是为了
,应该为“电子邮件”添加另一个输入改变他们的占位符,而不是作为提交按钮。他们的第一个条件语句是它应该在哪里“发生”;-)正是,正如我告诉OP我离开了他们;-)
<input id="contact-send-btn" type="submit" value="Send" name="email"/>
enctype="text/plain"
 $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';