My site has 4 forms all with the same “basic” php code meaning I’ve changed the coding so that it corresponds to the specific form. When someone views the form it sends a blank email, then when the fill out and submit the form it sends an email with the values. I know that in the code there are variables defined and then it says to email, what I can’t figure out is how to write the code that I know is missing that tells it to ONLY send the email if the form is filled out and submitted not just viewed. If I move the code that tells it to email up, it emails after every entry is filled in, so for example if it has three entries I would get an email for the first entry, the second entry gives me the the first and second entries, the third gives me the first, second, and third entries. So all I really need is the last one.
Here is my php and HTML code for one of my forms, I don’t know php really at all although I understand the “foreach ($_POST as $key => $value)” code is getting the value for each entry, which is why if I move the mail code up then I get an email “foreach” entry. I know there is code missing but I cannot figure out how to write it.
<?php $mailto = "[email protected]"; $subject = "Feedback Form"; $message = $_POST['message']; $header = "From: ".$_POST['email']; foreach ($_POST as $key => $value) { if (!is_array($value)) { $message .= "\n".$key." : ".$value; } } mail($mailto, $subject, $message, $header); ?>