我需要帮助,我正在尝试设置联系表单,我有代码并且认为我已经使用HTML和PHP正确设置了它。当我提交在我的测试网站上进行测试时,它会发送一封电子邮件,但电子邮件是空白的。
如果你能帮助我,请提前致谢。
HTML:
<div class="col-md-6 contact-right">
<form name="contactform" action="mailer.php" method="post" role="form" enctype="text/plain">
<div class="styled-input agile-styled-input-top">
<input type="text" class="form-control" name="name" placeholder="Your Name">
<label for="name">Name</label>
<span></span>
</div>
<div class="styled-input">
<input type="text" class="form-control" name="email" placeholder="Your Email">
<label for="email">Email</label>
<span></span>
</div>
<div class="styled-input">
<input type="text" class="form-control" name="subject" placeholder="Subject">
<label for="subject">Subject</label>
<span></span>
</div>
<div class="styled-input">
<textarea class="form-control" rows="4" name="message" placeholder="Your message..."></textarea>
<label for="message">Message</label>
<span></span>
</div>
<input type="submit" value="Submit" name="submit">
</form>
</div>
<div class="clearfix"> </div>
</div>
</div>
</div>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "laura@ironcladdesign.co.uk";
$subject = "Enquiry from CK9C Website";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! We will be in touch very soon";
?>
答案 0 :(得分:2)
问题在于:
<form name="contactform" action="mailer.php" method="post" role="form" enctype="text/plain">
您编码为&#34; text / plain&#34;。替换为&#34; application / x-www-form-urlencoded&#34;这是默认值,或者不包括enctype,这将是默认值。
答案 1 :(得分:-2)
您可以尝试代替$ _POST
if ((!is_array($_POST)) || (count($_POST) < 1)) {
$_POST = json_decode(file_get_contents('php://input'), true);
}