-1

I have a website and want people to be able to send me an email through a form. I have followed this tutorial here, but it doesn't send the email.

                        <?php
                            $name = $_POST['name'];
                            $email = $_POST['email'];
                            $message = $_POST['message'];
                            $from = 'From: FPSUsename.xyz';
                            $to = 'FPSUsername@outlook.com';
                            $subject = $_POST['subject'];

                            $body = "From: $name\n E-Mail: $email\n Message:\n $message";

                            if ($_POST['submit']) {
                                if (mail ($to, $subject, $body, $from)) { 
                                    echo '<p>Your message has been sent!</p>';
                                } else { 
                                    echo '<p>Something went wrong, go back and try again!</p>'; 
                                }
                            }
                        ?>

                        <form method="post" action="index.php">
                            <div class="field">
                                <label for="name">Name</label>
                                <input type="text" name="name" placeholder="Your Name">
                            </div>
                            <div class="field">
                                <label for="email">Email</label>
                                <input type="email" name="email" placeholder="Your Email">
                            </div>
                            <div class="field">
                                <label for="subject">Subject</label>
                                <input type="text" name="subject" placeholder="Subject"/>
                            </div>
                            <div class="field">
                                <label for="message">Message</label>
                                <textarea name="message" id="message" rows="4" placeholder="Message"></textarea>
                            </div>
                            <ul class="actions">
                                <li><input type="submit" id="submit" name="submit" value="Submit" /></li>
                            </ul>
                        </form>

This is the code, yet it always shows "Your message has been sent!" even when I haven't filled in anything. Could somebody help me?

FPSUsername
  • 17
  • 1
  • 8
  • 2
    Well, you haven't done any validation at all on the submitted data to make sure any fields contain anything. What did you expect? Also, you seem to have two different problems. Is the problem that it doesn't send mail when it should? Or that it says "Your message has been sent" when you leave the fields blank? – elixenide Oct 26 '15 at 20:21
  • it says "Your message has been sent" when you leave the fields blank But I fixed it with using required/ on every input field – FPSUsername Oct 26 '15 at 20:46

2 Answers2

0

You haven't got any validation on the function, so thats the reason for:

Your message has been sent!" even when I haven't filled in anything. Could somebody help me?

Also check your junk mail if you're not actually receiving the data.

I ran into this a few months ago, and learned that the host doesn't automatically try re sending messages all the time to clients, so this could be the bug also.

i am me
  • 89
  • 1
  • 14
0

Try to add validation .you don't need to add a jQuery validation you can add a very simple validation with required in your input field and then submit the form .After that check your spam folder .

Let me know if anything else i can help you.