我有一个 HTML5 表单,如下所示:
<form id="contact-form" action="php/email.php">
<fieldset>
<ul id="form">
<li>
<label for="name">Name:</label>
<input id="name" name="name" type="text" placeholder="First and Last Name" required />
</li>
<li>
<label for="email">Email:</label>
<input id="email" name="email" type="email" placeholder="Enter email address" />
</li>
<li>
<label for="message">Message:</label>
<textarea id="message" name="message" placeholder="Leave comments here..." required></textarea>
</li>
</ul>
<a id="back" href="index.html"><-- Home</a>
<input type="submit" id="submit" value="Submit Form" class="button"/>
</fieldset>
</form>
以及一个向我发送电子邮件的小型 PHP 脚本。我想知道如何将用户重定向到“谢谢”页面。有什么建议吗?
抱歉,这是 PHP 脚本:
<?php
$name = $_GET['name'];
$visitorEmail = $_GET['email'];
$message = $_GET['message'];
$email_from = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="48242d3b262129232a2208222931663f293b20222d2e2e662d2c3d" rel="noreferrer noopener nofollow">[email protected]</a>";
$email_subject = "New Form Submission! - From: " + $visitorEmail;
$email_body = "Here is the message from $name: \n $message";
$to = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd91988e93949c969f97bd979c84d38a9c8e9597989b9bd3989988" rel="noreferrer noopener nofollow">[email protected]</a>";
$headers = "From: $email_from \r \n";
$headers .= "Reply-To: $visitorEmail \r \n";
mail($to, $email_subject, $email_body, $headers);
echo "Success! You've sent mail!";
?>
编辑:
好的,我遇到的问题是:
~/MyMobileApp/php/email.php
以及我的所有内容:
~/MyMobileApp/
我想重定向回本地页面,即我的索引页面,该页面位于 php 脚本上方的一个文件夹中。 header 的问题是它不能超出当前所在的目录;也许我应该在该文件夹中添加一个感谢 html 页面并重定向?或者有更好的办法吗?
最佳答案
在您的 php 发送电子邮件后,添加以下 php 代码段:
header("HTTP/1.1 303 See Other");
header("Location: /thank-you.php");
exit();
关于php - HTML 表单 + PHP、页面重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9577523/