联系表格在网络邮箱中变为空白

时间:2016-04-01 14:06:06

标签: php html forms contact-form

我只是尝试在我的网站上使联系表格风格的html看起来不错,但我不知道如何使用PHP,因为它发送电子邮件到webmail得到空白信息,所以任何人都可以帮助我更好的PHP形式。感谢

<form id="main-contact-form" name="contact-form" method="post" action="sendemail.php">
                <div class="row  wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
                  <div class="col-sm-6">
                    <div class="form-group">
                      <input type="text" name="name" class="form-control" placeholder="Name" required>
                    </div>
                  </div>
                  <div class="col-sm-6">
                    <div class="form-group">
                      <input type="email" name="email" class="form-control" placeholder="Email Address" required>
                    </div>
                  </div>
                </div>
                <div class="form-group">
                  <input type="text" name="subjects" class="form-control" placeholder="Subject" required>
                </div>
                <div class="form-group">
                  <textarea name="message" id="message" class="form-control" rows="4" placeholder="Enter your message" required></textarea>
                </div>                        
                <div class="form-group">
                  <button type="submit" class="btn-submit">Send Now</button>
                </div>
              </form>  

此文件为sendemail.php

<?php $name = $_POST['name'];
$email = $_POST['email'];
$subjects = $_POST['subjects'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "admin@cybermediaclub.co.uk";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>

2 个答案:

答案 0 :(得分:0)

$formcontent="From: $name \n Message: $message";

这一行应该是:

$formcontent="From:" .  $name . "\nMessage:" . $message;

And $mailheader = "From: $email \r\n";

应该是

$mailheader = "From:". $email . "\r\n";

答案 1 :(得分:0)

对于这个主题,你没看到任何东西是正常的。因为它找不到变量$ subject:

$subjects = $_POST['subjects'];
...
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

而且我认为打破所有这就是你什么也看不见的原因。

解决方案:

mail($recipient, $subjects, $formcontent, $mailheader) or die("Error!");