联系表单php失败

时间:2015-02-15 12:48:28

标签: php html contact-form

我的联系表格有问题。测试时,我会收到一封没有内容的电子邮件。只是空输入标题"来自:(空)消息:(空)"。

PHP代码

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

HTML代码表格

<form method="post" action="mail.php">
                        <div class="row 50%">
                            <div class="6u">
                                <input name="name" placeholder="Name" type="text" class="text" />
                            </div>
                            <div class="6u">
                                <input name="email" placeholder="Email" type="text" class="text" />
                            </div>
                        </div>
                        <div class="row 50%">
                            <div class="12u">
                                <textarea name="message" placeholder="Message"></textarea>
                            </div>
                        </div>
                        <div class="row 50%">
                            <div class="12u">
                                <a href="mail.php" class="button alt">Send Message</a>
                            </div>
                        </div>
                    </form>

1 个答案:

答案 0 :(得分:0)

您没有传递表单,因为您只是使用mail.php链接到<a>。您的方式,$_POST将始终为空,因为您的表单未提交。

请更改此行

<a href="mail.php" class="button alt">Send Message</a>

<input type="submit" class="button alt" value="Send Message"/>