简体   繁体   English

PHP的电子邮件形式问题

[英]php email form issue

I am having trouble setting up a PHP form. 我在设置PHP表单时遇到问题。 Its my first try at doing this. 这是我的第一次尝试。 I have got the form to submit and send to my email. 我已经有表格提交并发送到我的电子邮件。 But i receive 2 emails. 但我收到2封电子邮件。

在此处输入图片说明

Is it ment to say (unknown sender) ???? 要说(未知发件人)吗? surely not. 当然不是。

在此处输入图片说明

and in this image it shows you that after only one form submit. 在此图像中,它显示了仅提交一个表单之后的情况。 it send one blank email, and one with text. 它发送一封空白电子邮件,另一封带有文本。 But only the message. 但是只有消息。 Whats wrong? 怎么了?

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "adamgoredesign@gmail.com";
$subject = "New Message";

mail ($to, $subject, $message, "From: " . $name);
echo "Your Message has been sent";

?>

      <form id="contactform" name="contact" method="post" action="#">
  <div class="row">
    <label for="name">Your Name<span class="req">*</span></label>
    <input type="text" name="name" id="name" class="text" tabindex="1" placeholder="enter name" required>
  </div>
  <br>
  <div class="row">
    <label for="email">E-mail Address<span class="req">*</span></label>
    <input type="email" name="email" id="email" class="text" tabindex="2" placeholder="address@domain.com" required>
  </div>
  <br>
  <div class="row">
    <label for="subject">Subject<span class="req">*</span></label>
    <input type="text" name="subject" id="subject" class="text" tabindex="3" placeholder="subject title" required>
  </div>
 <br>
  <div class="row">
    <label for="message">Message<span class="req">*</span></label>
    <textarea name="message" id="message" class="textarea" tabindex="4" required></textarea>
  </div>
  <br>
  <div class="row">
  <input type="submit" name="submit" value="Send Message" id="submit" />
  </div>
  </form>

The From header should be an email address or both a name and email address in the format: From标头应该是电子邮件地址,或者是名称和电子邮件地址,格式为:

From: John Smith <j.smith@gmail.com>

It should never be just a name, which is what you appear to be doing. 它永远不应只是名称,这就是您似乎正在做的事情。 Also remember to terminate headers with \\r\\n . 还记得用\\r\\n终止标题。

Using user input as the From header is not usually a good idea because it can introduce a header injection vulnerability, and it can also cause inconsistent spam filter results. 通常,将用户输入用作From头不是一个好主意,因为它可能会引入头注入漏洞,并且还会导致不一致的垃圾邮件过滤器结果。 For a contact form, I suggest just using a static email address of your own. 对于联系表格,我建议仅使用您自己的静态电子邮件地址。

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

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