hello again... Have to create 4 or 5 online forms for a website I built for my local area of NA. I found a basic HTML Form template at w3schools; & used that for my first form: https://www.burlingtoncountyna.org/gsr.report.html So...when users finish & hit the Submit button, the form (& all included info) needs to go to our secretary's e-mail. I've read everything I can get my hands on regarding PHP, but for a beginner coder such as myself...informationals on the web never tell you precisely *take this snippet...customize it thusly; & place it here*...even the instructionals on w3schools are vague on this topic (for people such as myself). So...can someone take a look at that form page; & point me in the right direction, at least? thanx mark4man
First, take an existing example and make it work. For example: https://html.form.guide/contact-form/php-email-contact-form/ You should rename your gsr.report.html to gsr.report.php or if you're going to use a test page, name it test.php Once you understand how the form in the example works, it will give you the confidence to adapt your own form to it.
In your HTML, you are using same "name" for each form field. When this form is submitted, it will only submit one last field, nothing else. Change the name="name" part in all these fields. <input type="date" name="name" /> <input type="text" name="name" /> will not work. This "name" can be anything you want, like: <input type="date" name="meeting_date" /> <input type="text" name="group_name" /> etc etc For checkboxes, use a name like this: <input type="checkbox" name="indicate_one[]" value="New Gsr" /> New GSR <input type="checkbox" name="indicate_one[]" value="proxy" /> Proxy Notice the "[]" sign in the name part. For the submit script, use something like this, with some more validation checks: This script has no validation checks. Find some functions online to verify email ids, date formats etc. <?php $m=""; foreach($_POST as $k=>$kk){ //validate data here //make your email message body if(!is_array($kk)){ $m.="$k = $kk\r\n"; }else{ $kk= implode(", ", $kk); $m.="$k = $kk\r\n"; } }//foreach loop ends //if all validations are ok, then send email to assistant $to= ""; $subject= "mail from website"; $from=""; $header="From: $from"; if( mail($to, $subject, $m, $h) ){ echo "Thanks your message is sent. We will contact you shortly."; }else{ echo "There was an error sending message, Please send an email with your question to $from "; } ?>
oops, just noticed, change the "$h" to "$header" in this line: if( mail($to, $subject, $m, $h) ){ change to: if( mail($to, $subject, $m, $header ) ){