我的电子邮件php表单有问题,当我点击提交按钮时,会出现另一个页面,上面写着There was a problem with your e-mail ()
我不知道我做错了什么?
这是我的代码:
html代码
<!-- Subscription Form -->
<form class="email" action="form.php" method="post">
<input class="get_notified" type="text" placeholder="Enter your email address ..."/>
<button type="submit" class="go" /></form>
<!-- End Subscription Form -->
</div>
</div>
</body>
php代码
<?php
$to = "email@mydomain.com";
$from = "email@mydomain.com";
$headers = "From: " . $from . "'r'n";
$subject = "New subscription";
$body = "New user subscription: " . $_POST['email'];
if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) )
{
if (mail($to, $subject, $body, $headers, "-f " . $from))
{
echo 'Your e-mail (' . $_POST['email'] . ') has been added to our mailing list!';
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
您需要在HTML表单中添加一个name="email"
字段,以便PHP能够使用$_POST['email']
获取它
<input class="get_notified" name="email" type="text" placeholder="Enter your email address ..."/>