Working Contact Form in PHP with Validation & Email Sending

Поделиться
HTML-код
  • Опубликовано: 26 янв 2025

Комментарии • 243

  • @FollowAndrew
    @FollowAndrew  4 года назад +31

    Something a bit different today: PHP contact form with email! Comment, like, & subscribe!!

    • @alexshel8578
      @alexshel8578 3 года назад +2

      it works with github pages server?

  • @matthewrobinson6183
    @matthewrobinson6183 3 года назад +8

    Huge thank you.
    I literally had no experience with PHP (at all) and I used your lesson to teach myself how to edit a form submission page PHP script generated by a block editor program (Nicepage) and get it to work first time!
    Crystal clear instruction.
    Thank you!

    • @toma1610
      @toma1610 2 года назад

      Have you include checkboxes or multiple select options in your form? Are you in Stackoverflow?

  • @Ditdee
    @Ditdee 4 года назад +2

    Thank you! Thank you ! Thank you! I just wrote this script and it works wonderfully. This is after getting 3-5K quotes from developers. I migrated servers and the old server was using an outdated "perl" script to process forms. I cannot tell you how helpful this video was for me! Thank you Andrew!!!

  • @nickkarsant9610
    @nickkarsant9610 3 года назад +13

    Ok, but how do you make to so you ACTUALLY receive an email, cuz that bit doesnt seem to work when i try it, nor do you show that.

  • @military_grade_dev7087
    @military_grade_dev7087 3 месяца назад

    Thank you so much, so many tutorials out there that do not work and yours was so easy to follow

  • @lizburke737
    @lizburke737 2 года назад

    Exactly what I needed! I know literally zero PHP but it worked first try. Thank you!

  • @toma1610
    @toma1610 2 года назад

    11:42 So, if you don‘t set the
    if isset function on the top, the form could be sent just with empty fields? Is for that the isset function?

  • @niteshsahni8393
    @niteshsahni8393 3 года назад

    i searched for this keyword and i found you and you know what you are awesome amazing

  • @BenAssane
    @BenAssane 4 года назад +6

    Follow andrew's tutorials are the best
    i have learned so much stuff in this channel !
    Hope you'll continue php tutorials and responsive tutorial with other projects 👌

  • @jeremyharvard6057
    @jeremyharvard6057 2 года назад

    Thanks man, this video really helped me! Thank ya very much! I never knew how that css thing worked, I used to think that's something of a js thing! Now I know it is a css property!

  • @jekath2786
    @jekath2786 4 года назад

    Thank you so much. One of the few people who explain php so good. :)

  • @somethingnew3338
    @somethingnew3338 Год назад

    You are great. I am happy I discovered your channel.

  • @shantichawhan9376
    @shantichawhan9376 4 года назад +2

    not working. Downloaded your form html, js, css etc. completed php but I keep receiving a 405 error when running the php/html on my local system and and 404 error when I am hosting my website . The mail cannot be sent or received. Could you tell what the problem is??

  • @shnam928
    @shnam928 4 года назад +2

    Your tutorials are different & very helpful, thanks a lot.

  • @Abhishekkumar-rt9ro
    @Abhishekkumar-rt9ro 3 года назад

    Your tutorials are really awesome thanks for the hard work you are putting in. Love from India

  • @iwandevisser6684
    @iwandevisser6684 2 года назад +1

    Hi Andrew, thanks for the tutorial! Everything worked for me up until the point where I start to add the last if, else and endif statements. I get a "localhost can't run this.. http 500 error" message when I reload. I'm running this via MAMP, is that the reason it doesn't work?

  • @easilyCoded
    @easilyCoded 3 года назад

    Thank you. Thank you. Thank you. Thank you so much for this video. You're the best teacher on net!

  • @michael_toms
    @michael_toms 2 года назад

    I am completely a novice at this, but your explanation is comprehensible. Thank you!

  • @ryansymons8915
    @ryansymons8915 4 года назад

    Another awesome tutorial.. now to finish off validation and get this bad boy online

  • @tannermartz6761
    @tannermartz6761 3 года назад +3

    is the code for this validation on the github because right now i can only find the html, (thanks for the help andrew!!)

  • @next_luke
    @next_luke 4 года назад +5

    How can I use this PHP with an external file?

  • @amarantakruger8902
    @amarantakruger8902 2 года назад

    Thanks for explaining the logic behind easy to understand!

  • @somethingnew3338
    @somethingnew3338 Год назад

    You explain very well and detailed.

  • @chome4
    @chome4 2 года назад

    How would you incorporate checkboxes in the php portion? I can add the html for checkboxes but can't seem to work out how to get 'check' to work.

  • @paulrak99
    @paulrak99 2 года назад

    Thank you for this! Quick question, all of the emails from my domain/host are forwared to my gmail account but they are all going to my spam folder. How do I fix this? Thank you for the help!

  • @paulsccna2964
    @paulsccna2964 4 года назад +3

    Posted this on my IIS server and it does not work. IT does not throw an error but the email is never received. I tried my godaddy domain, google and, yahoo and the email never arrives. I have been tried this email form on dozens of different configurations and servers and it never works.

    • @eve4524
      @eve4524 4 года назад +1

      Same here. Does anyone have idea why mail not received?

  • @evaprzybyla8955
    @evaprzybyla8955 2 года назад

    love the way you are explaining stuff! thank you

  • @dannyreg8405
    @dannyreg8405 3 года назад

    Your error messages don't work in the form. What am I not seeing? if (preg_match("/^[a-zA-Z-']*$/",$name)) {
    $nameErr = "Only letters and white space allowed";, I have this in my code, but it doesn't stop it on the bottom on the form and doesn't show the message here: span class="error" *

  • @BrooklynDesigne
    @BrooklynDesigne 3 года назад +2

    Why am I not receiving messages in my mail?

  • @livymarilyn509
    @livymarilyn509 2 года назад

    Very functional bro to send campaign emails.

  • @jakubfrei3757
    @jakubfrei3757 3 года назад +1

    Hi. Nice video. I have a question though.Is your validation part " $_POST['email'] != ' ' " like this necessary ? Because array is true only if its not empty right ? So if we write just " if($_POST['email']), it should do the same ?

  • @davidumansky5775
    @davidumansky5775 2 года назад

    Thank you very much this video help me a lot! interesting! and also you explain good and make it easy to understand.

  • @TriLiCiT
    @TriLiCiT 2 года назад

    Andrew. So I have Visual Studio Code along with my own host via Hostinger in which i made a temporary webform.php. However when I use your provided code in studio code than submit the data. I'm not getting an array. It literally is showing in the live preview in html format behind the form the PHP script...am i doing something wrong...how do i get the array showing like yours?

  • @madsarmannaspelund6377
    @madsarmannaspelund6377 9 месяцев назад

    How Do I change the css that you wrote?

  • @toma1610
    @toma1610 2 года назад

    What I don‘t catch is how does the «$message_sent» variable is related to the mail function. Semantically, yes, but how do I know if $message_sent = TRUE, really means that the message was sent? All the rest was explained nicely.

  • @_nightowl263
    @_nightowl263 2 года назад

    Amazing tutorial. Straightforward & to the point.

  • @sodiq_5
    @sodiq_5 2 года назад

    Thanks a bunch for this video. It worked on a live server.

  • @lc6509
    @lc6509 3 года назад

    I had follow everything you had said and in the beginning it was working but now my page is not loading properly.

  • @graybab
    @graybab 2 года назад

    This is exactly what I was looking for, thank you!

  • @maryknauth7333
    @maryknauth7333 3 года назад

    I have my html form written in my main html file, form action = "form-file.php"
    When I tested my form, I get an http error 500, with this in the console "console.warn('crbug/1173575, non-JS module files deprecated.');"
    What does this mean?

  • @The_SIGMA_MUSLIM
    @The_SIGMA_MUSLIM 4 года назад

    I don't know what I'm doing here, but I can tell you that this is so f*cking entertaining

  • @ShanDysigns
    @ShanDysigns 8 месяцев назад

    In the past I've always sent my form method to additional PHP page but I want to try to incorporate everything into the same page. I'm following along but in your download files I do not see the file where you typed the PHP code within the same document as your HTML. I see four files to download, and the web form.html file which I assume we're supposed to save as a PHP file does not have your PHP code from this video. What am I missing?

  • @Unknown-yl1do
    @Unknown-yl1do 4 года назад +1

    This is very very very helpful, specially going through the logic of the code that u typed everytime, it really makes it so clear and understandable. I cannot thank you enough for your effort. here's a like and a subscribe :)

  • @photoinshot1355
    @photoinshot1355 3 года назад

    Thanks for a great tutorial, works great after setting up sendmail in php and adding a from in the mail (using yahoo). However, after sending the email and getting the success message “Thanks we will be in touch” If I refresh the page the email is sent again, and I get the success message again but cannot see the form. How can this be fixed? Thanks

  • @marcoanjos6545
    @marcoanjos6545 Год назад

    in the example you succeeded sending the email with the commented line: mail($to, ......), but to works you have de not comment right?, i tried instead not commented that line, but didn't work for me, i had every line of code as you have have, but not works for me.

  • @bensonanyeteiarthur1825
    @bensonanyeteiarthur1825 2 года назад

    Thank you soo much. Mine worked perfectly. But i have a question: When i received the message in my mail, the username is that of my Server's instead of either a name. Can you pls help me with that.

  • @harshshah6648
    @harshshah6648 4 года назад

    Hello Sir, My name is harsh.
    i'm making a contact-us form with html, css and php.
    i have a question on 6:20
    sir can you tell me how can i write first and last name and phone number in $ form?
    example $userEmail = $_POST['email'];
    so can you explain me sir how to write this code?
    sir can you help me to figure out this code?

  • @A_ALI24
    @A_ALI24 2 года назад

    Thank you for your time and effort. Could you pls explain how to setup the smtp, server name, username, password, port number of the sender?

  • @kkroll7366
    @kkroll7366 4 года назад +1

    i followed your text exactly, and the form errors out.

  • @rashaadmyrieckes1506
    @rashaadmyrieckes1506 3 года назад

    2 questions ...1. i had to make a php doc. with my html code to see and be able to use my form, why doenst it work with my original index.html file and on my php file my css wont sho on it even with my link ....2. got my form to work but not sending to my email get error Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\

  • @nafijrohi01
    @nafijrohi01 2 года назад

    Great tutorial,Andrew -really things easier for me.

  • @dannyreg8405
    @dannyreg8405 3 года назад

    Andrew - Great Video, however, I couldn't find the video on the form itself. Can you direct me to it so the next time I can follow along?

  • @edal61
    @edal61 2 года назад

    Excellent tutorial, could not get the "php" code from the Github page you provided though, just the html version of the page. Is it available elsewhere? Thanks!

  • @봉bong
    @봉bong 3 года назад

    Hi, thank you for the good video, I copied it really easily, but I'm going to link the file I copied to the html file and put the context part under the html file, can you tell me how to do it?

  • @djb4programming
    @djb4programming 4 года назад +1

    Hi,
    It is not working for me at all.

  • @santiagoramirez5507
    @santiagoramirez5507 4 года назад

    Muchas gracias!! From Chile!! I appreciate your video so much!

  • @erikdinos1229
    @erikdinos1229 2 года назад

    nice work! but i need some help,with Greek characters..i see strange symbols instead of my Greek message.any one who has an idea to solve this issue? thanks in advice!

  • @K_MONEYHOUSE
    @K_MONEYHOUSE 4 года назад +1

    Hey Andrew can you help me i just buy cv portfolio the send message is not working how to fix this i'll send you the picture

  • @learnwithnorlyn
    @learnwithnorlyn 4 года назад +3

    Hi Sir! I really like how you explain things, keeping in mind that a lot of newbies might be checking this tutorial out. Thank you.
    I have a question, I created a landing page with a contact form. It has a file name index.html. I want to make the contact form work, should I then change it to index.php for it to be a fully funtioning contact form?

    • @mohamadSalahia
      @mohamadSalahia 4 года назад +1

      Yes change it to index.php and then make form validations and send email :)

    • @learnwithnorlyn
      @learnwithnorlyn 4 года назад +1

      @@mohamadSalahia Hey! That’s very kind of you. Thanks

    • @mohamadSalahia
      @mohamadSalahia 4 года назад +1

      @@learnwithnorlyn Your welcome :)

  • @IAmJesseJim
    @IAmJesseJim 4 года назад

    You didn't enable the mail(). Did it still send without it being in use?

  • @kenaida22
    @kenaida22 3 года назад

    How do i use this form on my site, and not in a local ht docs folder?

  • @tareboda-3436
    @tareboda-3436 3 года назад

    Hi.
    I would like to thank you for this video. Nicely explained.
    I would also ask if you have also working example of PHP form that would actually send an email to a customer who submitted the form, not only to the owner, but to both ...
    Thank you

  • @twissr
    @twissr 4 года назад +1

    Hey man, thank you for your videos! I'm learning a lot. This tutorial was easy to follow along and you also break everything down. this worked up until I took the comment on mail($to,$messageSubject,$body)
    $message sent=true;
    the browser spits !*Parse error: syntax error, unexpected '$message_sent' (T_VARIABLE) in C:\php\htdocs\Developer Layouts\webform.php on line 21*! out.
    Can you please explain what I missed?
    Also for a future video you could go over MySQL and how to stick the input of forms go into the database.
    Thanks again.

  • @ClarenceTavede
    @ClarenceTavede 3 года назад

    Hi andres I get this error message everytime: "method reflectionparameter::getclass is deprecated".
    How can i solve this?

  • @silverbell6160
    @silverbell6160 3 года назад

    Very clear, good information, great tutorial, thanks, I subscribed!

  • @brianjett1446
    @brianjett1446 2 года назад +1

    Before I start to watch this video for some reason I cannot send an email using Xampp.

  • @kudjoeerik1622
    @kudjoeerik1622 3 года назад

    Hi Andrew, I enjoyed your tutorial . I have a question.. how can you add attachment to the form to send email with attachments . Also can you connect this to MySQL to see the sent emails ? Thank you

  • @ylem_one
    @ylem_one 3 года назад

    I'm lost at saving the contact website. Should I save it as php or html? If I save it as php then my browser displays the code instead of a website. If I save it as html the code doesn't work. Where should I pin the php code? To webform.html or webform.php?
    Also when I add a class to an input:

    • @juliushermansen1851
      @juliushermansen1851 3 года назад

      Like he says in the start of the video. You need to run Xampp, of have the code running on a live server that has PHP installed. You computer can not natively localhost PHP files.

  • @jjswin
    @jjswin 3 года назад

    Hi @FollowAndrew, I just wanted to ask how secure this method is. Is this super secure, or are there 'more' secure ways of doing it?
    I'm handling sensitive data under UK GDPR so I'm conscious of using the most secure methods possible. Thank you!

  • @MohammedMakawy-Tech
    @MohammedMakawy-Tech 3 года назад

    how can i add the same form but with atachment input file?

  • @JulioTex
    @JulioTex 4 года назад +1

    Great tutorial, really helped me to understand forms and e-mail validation :)

  • @isaacbuckman258
    @isaacbuckman258 3 года назад

    Anytime i click on send message it takes me to the code

  • @malachi5813
    @malachi5813 2 года назад

    Well Done SIR!

  • @wazaa2008
    @wazaa2008 4 года назад +1

    Thanks for making this video! Is that email validation code in php also necessary when “required” is already used in the input HTML?

  • @missulu
    @missulu 2 года назад

    We do that. Happy to save you from the programming involved!lol! Email response and simple code generation.

  • @fd-daniel578
    @fd-daniel578 4 года назад

    I love your tutorial Andrew, Thank you for such detailed information on how we really do this! You're great man!

  • @jeffhardin3630
    @jeffhardin3630 3 года назад

    Didn't work. The "Thanks, We'll be in touch" message displays along side the contact form. Double checked my code and I can't find where I messed up!

  • @muhammadrashidkhan4595
    @muhammadrashidkhan4595 2 года назад

    Hi Andrew first of all thanks a lot for your excellent sharing. Video is excellent. I just want to highlight the diffulities I face to implement it.
    On your provided github repository there is no webform.php file present. One more thing to point, some description is required for the code in the main.js file. This main.js which is present on github repository.

  • @RicardoVanHouten
    @RicardoVanHouten 3 года назад

    I'm using PhpStorm and it doesn't allow me to put PHP tags separate with the "Else:" statement because of an error (expected statement) you need to make an else command to make it work can you help me?

    • @FollowAndrew
      @FollowAndrew  3 года назад

      Not sure I'm following, as the PHP should work anywhere. I don't use PHPStorm, so can't speak to what may be going on there?

  • @lt10offley
    @lt10offley 4 года назад

    Hey there, I am trying to submit the form so that it sends the relevant data to my email address. I have tried to use the recursive array to see if when I click on my submit button it spits out the relevant data. But I keep receiving a 405 error when running the php/html on my local system and and 404 error when I am hosting my website on a dynamic hosting service. This happens every time I go to submit the form. Any ideas what I'm doing wrong?
    Lewis

  • @ms.latosha2107
    @ms.latosha2107 3 года назад

    Hi sorry late to the party :) is there one that has the ability to upload I hear it mentioned in here... I would like to be able to receive pdfs, word docs, pics-jpeg, png, etc.., excel maybe Thank you

  • @rakgoshilekalakala4578
    @rakgoshilekalakala4578 Год назад

    so i don't need smtp server?

  • @rihasanatrofolo2472
    @rihasanatrofolo2472 3 года назад

    What song is that intro?

  • @marksiely4747
    @marksiely4747 2 года назад

    I am very glad to have come across your tutorials. Actually I was looking for a tutorial on how to add a subscribe and activate for newsletter . Can I use this tutorial for this purpose and what should i change to that ? Than you very much in advance

  • @jamesdb5596
    @jamesdb5596 4 года назад +3

    Great tutorial, Andrew - really made things easier for me :-)

  • @shjohnson2941
    @shjohnson2941 4 года назад

    Hello, I love the tutorial! However, I have a problem. Everything works perfectly, but when I receive the email all of the inputs are blank. Example, name comes back as 'Name: " with no context. Is there something else I must do on the back end of my server, outside of the php? I noticed you had a link to AJAX in your head, is this necessary for the form to function? Thanks!

  • @MrJ2amil
    @MrJ2amil Год назад

    everything work for me except i don't received any email.

  • @JonasBecker
    @JonasBecker 4 года назад +1

    Love the tutorial, thanks! As styling of select boxes sucks, I used divs with a little javascript. How could one use the selected list item as a variable? Thanks in advance!

    • @MasterofAardvarks
      @MasterofAardvarks 3 года назад

      you can set a class on virtually anything. for example -

  • @ortalpoz91
    @ortalpoz91 4 года назад +1

    Hello, I added this to my website and changed the .html to .php and it gives me a HTTP error 500, what did I do wrong?

    • @netneedingsystems2318
      @netneedingsystems2318 4 года назад

      PHP is strict, if you fail in just one puntuation it will brake the entire site displaying a 500 error. Check your syntax and follow his tutorial along. :)

  • @_aamir
    @_aamir 3 года назад

    Perfection! Great job! Amazing tutorial!

  • @josephaoga5170
    @josephaoga5170 2 года назад

    Thanks so much for this, it was awesome. It helped me a great deal. I hope you'll touch on phpMailer soon.

  • @jeffreydillen6900
    @jeffreydillen6900 4 года назад +1

    i dont get it why everyone works in .php and put the html code in there. When is do that I just get a white screen with all the coding. am I doing something wrong?

    • @lucasruiz7326
      @lucasruiz7326 4 года назад +2

      If you execute the .php local file in your browser, a white page opens showing the html code. You should maintain the .html if you’re working locally. When you finish your website, you should change .html to .php. Then, upload it to your hosting server. There, the website opens correctly. In conclusion, .php works if it’s uploaded to the server/hosting, not locally. Have a great day!

    • @jeffreydillen6900
      @jeffreydillen6900 4 года назад

      @@lucasruiz7326 ooohh Thankyou,!

  • @turgut-ch
    @turgut-ch Год назад

    You like to keep your php and HTML separate, then why you write them in the same file?

  • @Naveenkumar-te4id
    @Naveenkumar-te4id 4 года назад

    Great Work Andrew, it really helped me a lot... Thanks for this.

  • @eftiprwtopapadakis9310
    @eftiprwtopapadakis9310 4 года назад +1

    Amazing content as always and very helpful! Though, one question. How would you suggest with javascript to print the "thank you your form submitted" somewhere discreet in the same page where the user hasnt to redirect to another page

  • @paulm7917
    @paulm7917 3 года назад

    hi Andrew, by any chance you have the php code ?

  • @Persoxa
    @Persoxa 4 года назад

    How would you do it with options

  • @Joseph-yd3sq
    @Joseph-yd3sq 4 года назад

    Mine worked in local but when i uploaded it in live host i get SMTP error: could not authenticate. I'm using HostGator for my hosting. Can you help me Andrew? or someone here in comment section? btw thanks for this tutorial i really appreciate it.

  • @sifisomasilela6753
    @sifisomasilela6753 4 года назад

    One of the best Tuts. Thanks

  • @philipadams5386
    @philipadams5386 2 года назад

    Congratulations on this tutorial. I'm a PHP newbie but can follow along for the most part if I watch repeatedly. One question, however: Is adding the variable $body necessary? I think it is simpler to use $message as the third parameter of the mail function. Am I right?

    • @toma1610
      @toma1610 2 года назад +1

      Yes, also most of developers use $message as the third parameter and is REQUIRED. For semantic reasons, developers use: $to, $subject and $message as parameters names, for convention, but it doesn‘t have to be like this, necessarily. You saw how this video used $body instead of message, and $messageSubject instead of just $subject.
      You name them whatever you want, but three of them, in the strict order, have to be included. The first parameter is for the email destination of the form, that will go to the box of the TO in the mail application. The same for the SUBJECT. Whatever you put as the second parameter will go in the SUBJECT field of the email app.
      Additional headers are optional but recommended to get better organized. Obviously, when you called the mail functions, use the parameters names you are using: mail ($first_parameter_destination_email, $second_parameter_topic_name, $third_parameter_content_message);