gpt4 book ai didi

javascript - 将 html 表单数据发送到发件人的电子邮件

转载 作者:搜寻专家 更新时间:2023-10-31 21:01:35 24 4
gpt4 key购买 nike

我已经在 html 中创建了一个表单,并使用 php 脚本尝试将其发送到电子邮件,但它不起作用。你能检查一下我哪里错了吗?

每当我点击发送按钮时,它就会开始显示 php 代码,而不是将电子邮件发送到给定的电子邮件。

HTML
----


<!DOCTYPE html>
<html>
<head>
<title>Form</title> <!-- Include CSS file here -->
<link href="css/form.css" rel="stylesheet">
</head>
<body onload="myFunction()">

<h1> Form Request </h1>

<form name="contactform" action="email.php" method="post">

Name: <input type="text" name="full_name"><br \><br \>
Id: <input type="text" id="id"><br \><br \>
Email id: <input type="email" email="email"><br \><br \>
<a href="Form_IP.pdf" download>Download Blank Form </a> <br \><br \><br \>
Upload Filled Form<br \><br \>

<input type="file" id="myFile" multiple size="50" onchange="myFunction()">

<p id="resellerfile"></p>

<script>
function myFunction(){
var x = document.getElementById("myFile");
var txt = "";
if ('files' in x) {
if (x.files.length == 0) {
txt = "Select one or more files.";
} else {
for (var i = 0; i < x.files.length; i++) {
txt += "<br><strong>" + (i+1) + ". file</strong><br>";
var file = x.files[i];
if ('name' in file) {
txt += "name: " + file.name + "<br>";
}
if ('size' in file) {
txt += "size: " + file.size + " bytes <br>";
}
}
}
}
else {
if (x.value == "") {
txt += "Select one or more files.";
} else {
txt += "The files property is not supported by your browser!";
txt += "<br>The path of the selected file: " + x.value; // If the browser does not support the files property, it will return the path of the selected file instead.
}
}
document.getElementById("resellerfile").innerHTML = txt;
}
</script>
<br \><br \>

<input type="submit" value="Submit">



</form>
</body>
</html>

========================

    <?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {

//Email information
$admin_email = "xyx@submit.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$id = $_REQUEST['id'];

//send email
mail($admin_email, "$subject", $id, "From:" . $email);

//Email response
echo "Thank you for contacting us!";
}

//if "email" variable is not filled out, display the form
else {
?>

<form method="post">
Name: <input type="text" name="full_name"><br \><br \>
Id: <input type="text" id="id"><br \><br \>
Email id: <input type="email" email="email"><br \><br \>
<input type="submit" value="Submit" />
</form>

<?php
}
?>

最佳答案

它向您显示原始 php,因为浏览器不能直接执行 php 脚本,php 脚本 由服务器处理和执行,然后将 html 响应发送到浏览器。

因此,您需要在远程或本地服务器上托管 php 脚本。如果您想在系统本地设置服务器,请尝试安装 XAMP 或 WAMP。

请参阅下面的链接。

http://www.homeandlearn.co.uk/php/php1p3.html

关于javascript - 将 html 表单数据发送到发件人的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41118039/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com