Send Email with a Web Form: PHP Scripting + Form Validation


Video is ready, Click Here to View × – In this video we are gonna create a simple php script to process a web form, and take the information that somebody typed into it, and send you an email with that information.

Then, we are also gonna validate the form, so people won’t be able to submit it, unless they type in the required information. This form is gonna be fully functional by the end of this video.

Here is the video where I show you how to build the web…

42 thoughts on “Send Email with a Web Form: PHP Scripting + Form Validation

  1. Hello Mr: Greg How are you? Thank you for your tutorial I did as you said an everything is fine the problem that I see its the phone number doesn't show out in the email so can you please give me an idea of what's going on.

  2. Hi. Thank you so much for this video. I was able to get my form to submit to my email address thanks to your video. The question I have is, how can I specify the email address the form results are coming from? In my case it seems to be an arbitrary email from our company's account. I appreciate any insight you can provide.

  3. hi, i have used your php script to send form details from my website to the email. how ever my mails are not being sent? i double checked the code and is identical to yours. Does it hav anything to do with configuring smtp settings? if so how? please help.
    The code seems to be working as it fulfills the second condition that if anyone is directd to thank you page redirect them to contact.html page.. so on clicking submit, takes me to the top of contact page.

  4. Was a bit disappointed that it didn't work, but there was just a delay in the emails being sent. I can confirm this works.

    Chopped Orderform.php ————————-
        $emailBody = 'First Name: ' . $_POST['fname'] . 'n' .
                     'Last Name: ' . $_POST['lname'] . 'n' .
                     'Email: ' . $_POST['email'] . 'n' .    
                     'Comments: ' . $_POST['comments'];
        mail('','Subject Line', $emailBody);
        echo $emailBody;

    Chopped Order Form index.html —————

    <!DOCTYPE html>
    <form method="post" action="orderform.php">
      <label for="fname">FirstName:</label>
      <input type="text" name="fname" id="fname">
        <label for="lname">LastName:</label>
      <input type="text" name="lname" id="lname">
      <label for="email">Email:</label>
      <input type="email" name="email" id="email">
      <label for="comments">Comments:</label>
      <textarea name="comments" id="comments"></textarea>
      <input type="submit" name="submit" value="Send Message">

  5. Okay, my confirmation page shows up but I don't get an email. What am I doing wrong? I did it just like your video…. I've been trying to get this for months and I was so close to getting it but now something else goes wrong. I really need your assist if you would please. THANKS.

  6. Thank you very much! After watching tons of videos and getting nowhere, you've explained in simple and understandable way. And this wasn't the first video of yours that helped me. Thanks a lot!

  7. I did the same as the others, followed the tutorial word for word making an exact copy of the script, only to find it wouldn't work. After hours of searching & trying I changed the second line of code to if (!isset($_POST['submit'])) { I added an ! before isset & now it works. It may work for others too.

  8. I followed your tutorial and made an exact copy of your form and copy and uploaded it to my server. The problem is i get no email nor does it display the thank you page it simply sends me back to the contact page. Wtf????

  9. This seems to be the easiest method of collecting data from forms.. i have been researching how to get the data from my form to email for some time and i always seem to hit dead ends.However, when i tried to use your method on my site I dont get an email of the data nor does it direct me to the thankyou.html page. Instead it takes me to a plain page with the php scripting in it. Do you have any ideas on how to fix this. If you can help it will be amazing! If not, Do you know of any alternative methods?

  10. I really appreciate this video. It helped me out a lot. The only issue I have is that the email is coming in under the name of my nameserver for my host. What command can I put in so that the incoming email says the persons name in the heading instead of my nameserver? 

  11. I get this "Parse error: syntax error, unexpected ';', expecting ']' on line 11" which is the last line of the $body variable after ending it with a ; …I thought that's how you end lines in php? What am I missing? I have everything else as you have in your $body variable otherwise.

  12. Good tutorail. Nice easy and clear but having a problem with validation for InternetExplorer. (seems not work to work, at least not up to IE9)
    So it's a potential spam catcher 🙁 , any solution?


Leave a Reply

Your email address will not be published. Required fields are marked *