繁体   English   中英

PHP邮件表单不起作用

[英]PHP mail form is not working

我的电子邮件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 ..."/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM