表单提交打开php页面

时间:2015-11-01 19:54:19

标签: javascript php html

我在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

P.S。 :如果有人发现这是一个重复的问题,请评论它重复的问题的链接,以便得到我的答案。感谢

1 个答案:

答案 0 :(得分:3)

将用户发送回上一页:

header('Location: http://www.example.com/foo.php?back=yes'); //add your url

邮件调用后,删除脚本

on foo.php

if ($_GET['back']=='yes'){
echo '<script>alert("Your data has been submitted.");</script>';
}