我在 html 页面上有一个表单。它的操作为 mailer.php
。所有代码都工作正常,但提交后,页面转到 mailer.php,浏览器在屏幕上显示一个空白页面
contactus.html 表单标签:
<form id="form_20" action="mailer.php" method="post" target="_self"
enctype="multipart/form-data">
//input fields here
</form>
mailer.php 文件:
<?php
$to = '---------------'; //Removed for privacy
$subject = 'New Enquiry';
$name = $_POST['Name'];
$tel = $_POST['Number'];
$email = $_POST['Email'];
$comments = $_POST['Message'];
$body = "From: $name \nNumber: $tel \nEmail id: $email \nComments: $comments";
$headers = 'FROM: ---------------------------'.PHP_EOL; //Removed for privacy
mail($to, $subject, $body, $headers);
echo '<script>alert("Your data has been submitted.");</script>';
?>
代码工作正常,我也收到了邮件。 我遇到的唯一问题是页面重定向到 mailer.php
附注:如果有人发现这是一个重复的问题,请评论它重复的问题的链接,以便我得到答案。谢谢
最佳答案
将用户返回到上一页:
header('Location: http://www.example.com/foo.php?back=yes'); //add your url
邮件调用后,删除脚本
在 foo.php
if ($_GET['back']=='yes'){
echo '<script>alert("Your data has been submitted.");</script>';
}
关于javascript - 表单提交打开php页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33466510/