PHP邮件表单不起作用

时间:2013-11-28 17:39:27

标签: php forms email

我的电子邮件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 code

<?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'] . ')';   
}

1 个答案:

答案 0 :(得分:3)

您需要在HTML表单中添加name="email"字段,以便PHP能够使用$_POST['email']

获取它
<input class="get_notified" name="email" type="text" placeholder="Enter your email address ..."/>