[英]How can I post innerHTML to my email using a PHP form?
我正在使用包含名字、姓氏、Email 地址、电话和密码的注册表单。 提交上的注册表将数据发布到 myemail@domain.com。
最近我使用 Javascript 创建了一个 function 以允许用户生成密码,而不是将其作为文本形式的输入字段输入。 以前,用户输入的密码是输入字段。 密码是按照名字、姓氏、Email 地址和电话的发送方式发送的。 我正在使用 PHP function POST 用户在输入字段中输入的密码。
但是,在创建密码生成器脚本后,该脚本使用 function createPassword 生成用户密码,密码是在 ID 为“passwordBox”的 Div 中创建的。 passwordBox.innerHTML = 密码。
我现在无法将密码发布到 myemail@domain.com。 当然,我正在做一些错误的事情。
我正在寻找一些帮助,以便使用 PHPA3841AB4074D76 将 passwordBox.innerHTML 的 output 发布到我的 email
我在下面给出了表格的完整代码,以及 javascript。
高级开发人员的帮助将帮助我为人类解决这个关键的解决方案。
谢谢你。
<form action="index.php" id="contact-form" method="POST">
<input type="text" name="firstname" id="firstname" placeholder="First Name" class="form-control-2" autocomplete="off" required>
<input type="text" name="lastname" id="lastname" placeholder="Last Name" class="form-control-2" autocomplete="off" required>
<input type="text" name="email" placeholder="Enter Email Address" class="form-control-2" autocomplete="off" required>
<input type="tel" name="tel" id="phone" placeholder="Enter Phone Number" class="form-control-2" required>
<div id ="passwordBox"> THIS IS WHERE THE SCRIPT CREATES A RANDOM PASSWORD USING JAVASCRIPT.
</div>
<button type="button" onclick="createPassword()">Generate Password</button>
<button id="contact-submit" type="submit" name="submit" id="submit" data-loading-text="Sending..." class="btn form-cta">Submit</button>
</form>
<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$mailFrom = $_POST['email'];
$phone = $_POST['tel'];
$password = $_POST['password'];
$mailTo = "myemail@domain.com";
$headers = "From: ".$mailFrom;
$subject ="New Lead From $name";
$emailbody = "
You have received a new enquiry from
First Name: $firstname\n".
"Last Name: $lastname\n".
"User Phone: $phone\n".
"User Email: $mailFrom\n".
"Password: password\n";
?>
<script>
const keys = {
upperCase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
lowerCase: "abcdefghijklmnopqrstuvwxyz",
number: "0123456789",
symbol: "!@#$%^&*()_+~\`|}{[]:;?><,./-="
}
const getKey = [
function upperCase() {
return keys.upperCase[Math.floor(Math.random() * keys.upperCase.length)];
},
function lowerCase() {
return keys.lowerCase[Math.floor(Math.random() * keys.lowerCase.length)];
},
function number() {
return keys.number[Math.floor(Math.random() * keys.number.length)];
}];
function createPassword() {
const upper = document.getElementById("upperCase").checked;
const lower = document.getElementById("lowerCase").checked;
const number = document.getElementById("number").checked;
if (upper + lower + number === 0) {
alert("Please check atleast one box!");
return;
}
const passwordBox = document.getElementById("passwordBox");
const length = document.getElementById("length");
let password = "";
while (length.value > password.length) {
let keyToAdd = getKey[Math.floor(Math.random() * getKey.length)];
let isChecked = document.getElementById(keyToAdd.name).checked;
if (isChecked) {
password += keyToAdd();
}
}
passwordBox.innerHTML = password;
}
</script>
使用下面的 PHP 代码,它应该适合你。 我已将 JS var output 存储到 PHP 变量中,然后在 PHP 代码中使用它
<?php
$pass = "<script>document.write(password)</script>";
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$mailFrom = $_POST['email'];
$phone = $_POST['tel'];
$password = $_POST['password'];
$mailTo = "myemail@domain.com";
$headers = "From: ".$mailFrom;
$subject ="New Lead From $name";
$emailbody = "
You have received a new enquiry from
First Name: $firstname\n".
"Last Name: $lastname\n".
"User Phone: $phone\n".
"User Email: $mailFrom\n".
"Password: $pass\n";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.