简体   繁体   中英

php email form issue

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>

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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