【发布时间】:2021-01-22 10:10:15
【问题描述】:
当我的联系表单中的消息已发送但我不知道该怎么做时,我想要重定向(到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:./index.php"); exit();。但是,您不能在此调用之前回显任何内容。因此,您必须先删除echo行...或使用其他方法对其进行管理 -
感谢您抽出时间 Gowire。那么我必须把回声放在哪里?