1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

HTML Form...Submit to E-Mail

Discussion in 'PHP' started by mark4man, Nov 8, 2020.

  1. #1
    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
     
    mark4man, Nov 8, 2020 IP
    JEET likes this.
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,151
    Likes Received:
    1,656
    Best Answers:
    29
    Trophy Points:
    475
    #2
    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.
     
    qwikad.com, Nov 9, 2020 IP
    JEET likes this.
  3. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    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 ";
    }
    ?>
     
    JEET, Nov 9, 2020 IP
    Efetobor Agbontaen likes this.
  4. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #4
    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 ) ){
     
    JEET, Nov 10, 2020 IP