php form send to email

  • Answered
I am reviewing your php email form code. You have validation code, send email code and form coding. Does it matter what order the php code is in? My thought is that the validation code should proceed the form code then the send to email code. I appreciate the help.
Hello, and thanks for your question. I believe you might be talking about our create a custom PHP contact form with validation guide. The order of the PHP code itself on that page should work fine, but you could possibly re-order it for your own needs if it's easier to think about that way for you. For instance the validation code is at the top, but this could also come after the HTML form itself if you wanted it to. PHP code is processed from top to bottom, so the order of your code can matter, but in this case you'll see the first line of the validation code is checking to see if we've submitted the HTML form yet:
if (isset($_REQUEST['submitted'])) {
So even if this code is above our HTML form code, it won't actually run until the form has been submitted. So we setup the validation code, then the code to send the email if validation passes, then some error reporting code, and finally the HTML form code itself. I hope that makes sense, please let us know if you had any further questions at all. - Jacob