php - 使用 PHP 发送消息后重定向到主页
问题描述
index.php
当我的联系表单中的消息已发送但我不知道该怎么做时,我想重定向(到我的主页),所以我请求您的宝贵帮助。
这是我的PHP代码:
<?php
$to = "test@test.me";
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$subject = $_REQUEST["subject"];
$msg = $_REQUEST["message"];
if (isset($email) && isset($name)) {
$website = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$name." <".$email.">\r\n"."Reply-To: ".$email."\r\n" ;
$msg = "Bonjour Anne-Valérie, <br/> <br/> vous avez un nouveau message de $name ($email)<br/><br/>Message: $msg <br><br> -- <br>Cet email a été envoyé depuis $website";
$mail = mail($to, $subject, $msg, $headers);
if($mail)
{
echo 'Votre mail a bien été envoyé, une réponse vous sera apporté sous peu, merci de votre confiance.';
}
else
{
echo "Oups, quelque chose n'a pas fonctionné, veuillez vérifier vos informations.";
}
}
?>
解决方案
如果你想重定向使用header("Location: http://example.com/myOtherPage.php");
. 这个问题已经回答了如何在 PHP 中进行重定向?一探究竟 。
推荐阅读
- javascript - 如何从缓存中删除用户
- git - 如何添加子模块,但覆盖主机 repo 上的文件?
- go - Golang 删除双斜杠并触发 GET 而不是 POST 请求,我如何在 Cloud Functions 中跳过这个?
- amazon-web-services - 如何在 Cloudformation 模板/CDK 中添加 AWS IoT 配置模板
- java - 无法将工件 io.confluent:kafka-connect-storage-common-parent:pom:6.0.0-SNAPSHOT 从/到融合(${confluent.maven.repo})
- asp.net - 如何阅读支付结果 MVC 的页面响应
- postman - 无法从 api 响应中获取属性
- google-app-engine - 使用 opencensus ext 时出现 Google App Engine 错误
- bash - 省略heredoc的注释
- python - 无法通过串口从 micro-python repl 挂载 sd 卡