简体   繁体   English

PHP联系表格没有内容

[英]PHP Contact Form Has No Content

The contact form I'm trying use is only sending the subject fields but no content. 我尝试使用的联系表单仅发送主题字段,但不发送任何内容。

I am using the following form: 我正在使用以下形式:

<form id="contact-form-face" class="clearfix"      action="http://www.demo.com/php/contactengine.php">
                            <input type="text" name="email" value="Email"     onFocus="if (this.value == 'Email') this.value = '';" onBlur="if (this.value == '') this.value = 'Email';" />
                            <textarea name="message" onFocus="if (this.value     == 'Message') this.value = '';" onBlur="if (this.value == '') this.value = 'Message';">Message</textarea>
                            <input class="contact_btn" name="submit"     type="submit" value="Send Message" />
                        </form>

And the PHP post: 和PHP帖子:

<?php

$EmailFrom = "myemail";
$EmailTo = "myemail";
$Subject = "";
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 

// validation
$validationOK=true;
if (!$validationOK) { 
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}

// prepare email body text
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

Any help would be greatly apprenticed 任何帮助将不胜枚举

You're not defining a method on your form, this results in the "message" and "email" values being sent as GET parameters, this means they become query parameters as part of the URL. 您没有在表单上定义方法,这导致“ message”和“ email”值作为GET参数发送,这意味着它们成为查询参数作为URL的一部分。 In order to get the form to send it's inputs to the $_POST, you must set the form action like so: 为了使表单将其输入发送到$ _POST,您必须像这样设置表单操作:

<form id="contact-form-face" class="clearfix" action="http://www.demo.com/php/contactengine.php" method="post">

Furthermore you have a typo on the recieving end, where you look for $_POST["Message"] but in the form you specify the name as "message". 此外,在接收端您有一个错字,您会在其中寻找$ _POST [“ Message”],但以格式将名称指定为“ message”。 These must match. 这些必须匹配。

//Edit - To implement an alert popup instead of a redirect change the if condition at the end of your script as follows: //编辑-要实现警报弹出而不是重定向,请在脚本末尾更改if条件,如下所示:

if ($success) {
    ?>
    <script>
        alert("Success!");
    </script>
    <?php
}
else{
    ?>
    <script>
        alert("Failure!");
    </script>
    <?php
}

You are using 您正在使用

$_POST['Message']

It should be: 它应该是:

$_POST['message']

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

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