php电子邮件表单问题 [英] php email form issue

查看:92
本文介绍了php电子邮件表单问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法设置PHP表单。这是我第一次尝试这样做。我有表单提交并发送到我的电子邮件。但是我收到2封电子邮件。

I am having trouble setting up a PHP form. Its my first try at doing this. I have got the form to submit and send to my email. But i receive 2 emails.

是否说(未知的发件人)????

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>


推荐答案

From 标题应该是一个电子邮件地址,或者是一个名称和电子邮件地址,格式如下:

The From header should be an email address or both a name and email address in the format:

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

它不应该只是一个名字,这是你似乎在做什么。还要记住使用 \r\\\
终止标题。

It should never be just a name, which is what you appear to be doing. Also remember to terminate headers with \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. For a contact form, I suggest just using a static email address of your own.

这篇关于php电子邮件表单问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆