简体   繁体   English

尝试从 html 输入中获取发布数据并通过 php 将其作为消息发送到电子邮件中

[英]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.当我输入一个 x 数字并单击提交时,2 个字段会打开 x 次我必须填写。 After that I am using php to get the post values but I do not know how to use all the array values.之后我使用 php 来获取 post 值,但我不知道如何使用所有数组值。 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.不知道如何从 javascript 获取所有数组值并将它们传递到我的 php 文件中。

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. $_POST 中的键是您输入的名称。 Eg例如

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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