简体   繁体   中英

trying to get post data from html input and send it in email as a message via php

I am doing a registration form. When i enter an x number and click submit, 2 fields open up x number of times that I have to fill. After that I am using php to get the post values but I do not know how to use all the array values. I have to send the all the values of each students class number and name in the message content via an email. In my email I am only getting the last input of the fields not all of them. Not sure how to get all of the array values from the javascript and pass them into my php file.

a section of html file's javascript 



var i;
        for (i = 0; i < ax; i++) {
            parent.insertAdjacentHTML(
                "beforeend",


"<div class=input>Enter student" +[i]+ "'s name:   <input type='text ' name='s_name[]' required></div>" +
                "<div class=input>Enter student" +[i]+ "'s class:   <input type='text ' name= 's_class[]' required></div>"
            );
        }


php code
$s_name=$_POST["s_name"];
$s_class=$_POST["s_class"];

$from = "zasas.com";
$to = $_POST["email"];
$subject = "asasas";
$message = "Name: ".$username."\r\n";
$message .= "student name: $s_name[i] \r\n";
$message .= "class: $s_class[i] \r\n";
$message .= "Your super id: aiorouehr \r\n";
$headers = "From: " . $from;

The keys in $_POST are the names of your input. Eg

<input type="text" name="myCustomKey" value="Micky Mouse">

<?php echo $_POST["myCustomKey"]; //returns Micky Mouse ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM