php - 使用 PHP 邮件处理程序提交表单后如何刷新页面
问题描述
通过 PHP 邮件处理程序指令从联系表单提交数据后,即使电子邮件发送正常,整个页面也会变为空白。按“F5”键刷新页面,但我宁愿系统自动执行此操作,而不是打扰用户。
我尝试在 if(isset) 行之后立即使用 header 函数,如下所示:
[code]
if(isset($_POST['submit']))
{
header("Location: https://amacwebsolutions.com");
}
[/code]
我是否将重定向代码放在错误的位置,还是需要完全不同的解决方案?
这是完整的 PHP 代码:
[code]
<?php
if(isset($_POST['submit'])) {
{
header("Location: https://amacwebsolutions.com");
}
$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$msg=$_POST['msg'];
$to='info@amacwebsolutions.com';
$subject="RE: ".$subject;
$message="Name: ".$name."\n"."Wrote the following: "."\n\n".$msg;
$headers="From: info@amacwebsolutions.com\r\nReply-To: $email";
if(mail($to, $subject, $message, $headers)){
echo "<h1>Sent succesfully! Thank you,".$name." We will contact you shortly!</h1>";
}
else {
echo "Something went wrong!";
}
}
?>
[/code]
解决方案
通过将标头置于 if 条件中来尝试此操作。
if(isset($_POST['submit'])) {
$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$msg=$_POST['msg'];
$to='info@amacwebsolutions.com';
$subject="RE: ".$subject;
$message="Name: ".$name."\n"."Wrote the following: "."\n\n".$msg;
$headers="From: info@amacwebsolutions.com\r\nReply-To: $email";
if(mail($to, $subject, $message, $headers)){
echo "<h1>Sent succesfully! Thank you,".$name." We will contact you shortly!</h1>";
header("Location: https://amacwebsolutions.com");
} else {
echo "Something went wrong!";
}
}
推荐阅读
- oracle - 我可以在光标中使用 BFILENAME 来处理多个图像吗?
- sql - How to get unique combinations
- symfony - 如何使用 twig 中的排序过滤整数
- html - ipad safari 中跨度的单击事件
- python - 区分肯定句和否定句
- python - 如何使用熊猫日期时间将数字转换为日期(通过使用这些数字作为与今天日期的距离)
- angular - 带有ceisum的角度8.1无法设置未定义的属性“自动链接器”
- javascript - 如何从私有函数访问组件范围?
- python - 在 Python 中使用 Beautifulsoup4 进行异步 HTML 解析
- git - Git:如何仅提取文件大小写更改?