简体   繁体   English

提交HTML表单后,$ _POST变量中没有值

[英]No values in $_POST variable after Submit HTML form

I have a html form, which is sending the data through POST to the php-file, and the php-file should process the data (make a good looking structure) and send it via mail. 我有一个html表单,它通过POST将数据发送到php文件,php文件应该处理数据(制作一个漂亮的结构)并通过邮件发送。

But the $_POST variable is completely empty.... 但是$ _POST变量是完全空的....

I have this small html form: 我有这个小的HTML格式:

<form id="form" method="post" action="formmailer.php">
            <div id="input1">
                <input name="name" type="text" placeholder="Ihr Name"> <br>
                <input name="email" type="email" placeholder="Ihre E-Mail"> <br>
            </div>
            <div id="input2">
                 <textarea name="nachricht" rows="10" cols="30"></textarea> <br>
                 <input type="submit" value="" name="submit" id="submit">
             </div>
</form>

And formmailer.php uses these variables: 而formmailer.php使用以下变量:

<?php // 

if(isset($_POST['nt']) && isset($_POST['ntb'])) 
{


// 
$an = "info@website.de";
$name = $_POST['name'];
$email = $_POST['email'];
$nachricht = $_POST['nachricht'];

// Mailheader UTF-8 
$mail_header = 'From:' . $email . "n";
$mail_header .= 'Content-type: text/plain; charset=UTF-8' . "rn";

// create layout
$message = "
Name:       $name 
Email:      $email 
Nachricht:  $nachricht 
";

// send mail
mail($an, $message, $mail_header );
}
else {
   echo("<p>Email delivery failed…</p>");
  }

?>

If i use this if-statement 如果我使用这个if语句

if (isset($_POST["submit"]))

the mail is sending, but completely empty. 邮件正在发送,但完全是空的。

Am i blind? 我瞎了吗? It should be really easy, shouldn't it? 应该真的很容易,不应该吗?

isset($_POST['nt']) && isset($_POST['ntb'])

In html I do not find nt and ntb field. 在HTML中我找不到ntntb字段。

When you use isset($_POST["submit"]) . 当你使用isset($_POST["submit"]) In Post array php find submit value. Post数组php中查找submit值。 But you did not enter any value in the form fields that is why you getting empty value in your mail. 但是您没有在表单字段中输入任何值,这就是您在邮件中获取空值的原因。

Replace this line from formmailer.php 将此行替换为formmailer.php

if (isset($_POST['nt']) && isset($_POST['ntb']))

to: 至:

if ($_POST)

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM