[英]PHP Contact Form Has No Content
我嘗試使用的聯系表單僅發送主題字段,但不發送任何內容。
我正在使用以下形式:
<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>
和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\">";
}
?>
任何幫助將不勝枚舉
您沒有在表單上定義方法,這導致“ message”和“ email”值作為GET參數發送,這意味着它們成為查詢參數作為URL的一部分。 為了使表單將其輸入發送到$ _POST,您必須像這樣設置表單操作:
<form id="contact-form-face" class="clearfix" action="http://www.demo.com/php/contactengine.php" method="post">
此外,在接收端您有一個錯字,您會在其中尋找$ _POST [“ Message”],但以格式將名稱指定為“ message”。 這些必須匹配。
//編輯-要實現警報彈出而不是重定向,請在腳本末尾更改if
條件,如下所示:
if ($success) {
?>
<script>
alert("Success!");
</script>
<?php
}
else{
?>
<script>
alert("Failure!");
</script>
<?php
}
您正在使用
$_POST['Message']
它應該是:
$_POST['message']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.