Javascript html脚本无法将表单的投诉值发送到php脚本
以下是HTML代码:-Javascript html脚本无法将表单的投诉值发送到php脚本,javascript,php,html,Javascript,Php,Html,以下是HTML代码:- 函数hello(最小值、最大值){ var x; x=数学地板(数学随机()*(最大最小+1)+最小); document.getElementById(“投诉”).value=x; //文件。编写(x); }; 姓名: 电邮: 请尝试下面的代码。我已经修改了JS部分,并且在submit按钮之前放置了隐藏字段。现在很好用 <html> <body bgcolor="#ccccb3"> <center> <form act
函数hello(最小值、最大值){
var x;
x=数学地板(数学随机()*(最大最小+1)+最小);
document.getElementById(“投诉”).value=x;
//文件。编写(x);
};
姓名:
电邮:
请尝试下面的代码。我已经修改了JS部分,并且在submit按钮之前放置了隐藏字段。现在很好用
<html>
<body bgcolor="#ccccb3">
<center>
<form action="http://localhost/PHPMailer-master/" method="post">
<p>Name:<input id="n" placeholder="Name" name="n" required></p>
<p>E-Mail: <input id="e" placeholder="Email Address" type="email" name="e" required></p>
<p><textarea id="m" placeholder="write your message here" name="m" rows="10" required></textarea></p>
<input type="hidden" value="100" id="complaint" name="complaint">
<p><input id="mybtn" type="submit" value="Submit Form" onClick="hello(112,78945)"></p>
</form>
</center>
<script type="text/javascript">
function hello(min,max) {
var complaint = document.getElementById("complaint").value
console.log(complaint);
};
</script>
</body>
</html>
姓名:
电邮:
函数hello(最小值、最大值){
var投诉=document.getElementById(“投诉”).value
控制台日志(投诉);
};
您的代码存在重大安全漏洞;请阅读SQL注入点击按钮触发表单提交。在这种情况下,不应期望浏览器执行其他脚本任务。这到底是为了什么?如果您只需要一个随机值,那么最好直接在PHP中创建一个…@Rushikumar:SQL注入漏洞在哪里?@David accessing$\u POST superglobaldirectly@Rushikumar:听起来您可能想了解SQL注入。你似乎不知道这个词的意思。
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'example@gmail.com'; // SMTP username
$mail->Password = '*******'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
if( isset($_POST['n']) && isset($_POST['e']) && isset($_POST['m']) ){
$n = $_POST['n'];
$e = $_POST['e'];
$m = nl2br($_POST['m']);
$c = $_POST['complaint'];}
else{
$n='';
$e='';
$m='';
$c='245';
}
$mail->setFrom('noreply@gmail.com', 'Panasonic');
$mail->addAddress('testpanasoniccontact@gmail.com', 'Pragzz'); // Add a recipient
//$mail->addAddress('ellen@example.com'); // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Complaint Number: '.$c;
$mail->Body = '<b>Name:</b> '.$n.' <br><b>Email:</b> '.$e.' <p><b>Message: </b>'.$m.'</p>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent. Your complaint will be attended within 48 hours. Your complaint No. is '.$c;
}
?>
<html>
<body bgcolor="#ccccb3">
<center>
<form action="http://localhost/PHPMailer-master/" method="post">
<p>Name:<input id="n" placeholder="Name" name="n" required></p>
<p>E-Mail: <input id="e" placeholder="Email Address" type="email" name="e" required></p>
<p><textarea id="m" placeholder="write your message here" name="m" rows="10" required></textarea></p>
<input type="hidden" value="100" id="complaint" name="complaint">
<p><input id="mybtn" type="submit" value="Submit Form" onClick="hello(112,78945)"></p>
</form>
</center>
<script type="text/javascript">
function hello(min,max) {
var complaint = document.getElementById("complaint").value
console.log(complaint);
};
</script>
</body>
</html>