【发布时间】:2016-05-12 02:39:35
【问题描述】:
所以我有一个模式表单,我想在其中获取输入的字段并将其发送到我想要的电子邮件地址,然后将其重定向到某个网页/下载页面 我已经设法用 PHP 做到了,但是我想使用客户端重定向它,只使用 PHP 邮件进行字段解析以获取电子邮件,我必须创建大量 PHP 表单才能这样做,因为重定向 url 在很多情况。
这里是 PHP
$to = "some@email.com";
$subject = "Contact Page";
$headers = "From: Contact Page";
$forward = 1;
$location = "somelocation";
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$msg = "Below is the result of your feedback form. It was submitted on $date at $time.\n\n";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
mail($to, $subject, $msg, $headers);
if ($forward == 1) {
print("You will be redirected to your download link shortly";)
header ("Location:$location");
}
else {
include("index.html");
}
现在是 html
<!-- Modal content -->
<div class="modal-content">
<span class="close">x</span>
<form method="POST" onsubmit="myFunction()" action="form2.php">
<label for='name'>Name: </label>
<input type="text" name="name" >
<label for='email'>Email: </label>
<input type="text" name="email" >
<input type="submit" id="submit" value="Submit" name="submit">
<script>
function myFunction() {
alert("form Submitted Successfully you will be redirected shortly");
}
</script>
【问题讨论】:
-
您想使用 Javascript 重定向页面吗?此外,您应该使用更好的标点符号来编写您的问题。这样更容易阅读。
-
结束标签在哪里?截至目前,您在表单中拥有 JavaScript 代码。
标签: javascript php html ajax forms