我一直在弄清楚我的代码有什么问题。我一直$_POST
不工作。这是我的 HTML 代码:
<form id="EmailForm" action="mailForm.php" method="post"
onsubmit="validateForm()" enctype="text/plain">
<div>
Name: <input type="text" value="" name="name" size="30" />
Email: <input type="text" value="" name="email" size="30" />
Subject: <input type="text" value="" name="subject" size="60" />
Message: <br />
<textarea name="message" rows="5" cols="60"></textarea>
<input type="submit" value="Send" />
</div>
</form>
这是我的mailForm.php
代码:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$mailsent = mail("admin@example.com", "$subject", "$message\n\n$name\n$email", "");
if ($mailsent) {
echo ("Your email has been sent. Thank you for using our mail form. <br />");
echo ("Name: ".$name."<br />");
echo ("Email: ".$email."<br />");
echo ("Subject: ".$subject."<br />");
echo ("Message: ".$message);
}
?>
到目前为止,我可以发送电子邮件,但所有电子邮件都是空的。名称或电子邮件未显示,但已从网络托管服务更改为默认名称。没有名字,没有电子邮件,没有主题,没有消息。在mailForm.php
,我只得到以下内容:
Your email has been sent. Thank you for using our mail form.
Name:
Email:
Subject:
Message:
我试过echo $_POST["name"]; echo $_POST["email"]
了,但是页面是空的。