Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我有一个php表单邮件脚本,可以将文本消息返回到浏览器。需要.php代码重定向到html页面_Php_Html_Redirect_Contact Form - Fatal编程技术网

我有一个php表单邮件脚本,可以将文本消息返回到浏览器。需要.php代码重定向到html页面

我有一个php表单邮件脚本,可以将文本消息返回到浏览器。需要.php代码重定向到html页面,php,html,redirect,contact-form,Php,Html,Redirect,Contact Form,这是HTML部分代码 <input type="hidden" name="recipient value="msheree@msascodesignsolutions.com"> <input type="hidden" name="subject" value="Submission" /> <input type="hidden" name="redirect" value="thankyou.html" /> <input

这是HTML部分代码

  <input type="hidden" name="recipient   value="msheree@msascodesignsolutions.com">
  <input type="hidden" name="subject" value="Submission" /> 
  <input type="hidden" name="redirect" value="thankyou.html" />
  <input type="hidden" name="projectinquiries" value="projectinquiries">
  <div class="btn-group">
  <a class="btn btn-default" href="mailto:email@emailaddress.com?Subject=Hello, %20Interested%20In%20A%20Quote" target="_top" role="button">Contact</a>
  <input class="btn btn-default" type="reset" value="Reset">
  <input class="btn btn-default" type="submit" value="Submit">
  …..

既然您提到您不懂PHP,我就在这里略谈一些技术细节

将其放在PHP脚本末尾的PHP标记中,将URL替换为要链接到的URL:

header('Location: http://www.msascodesignsolutions.com/thankyou.html');
最后几行应该是这样的:

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
header('Location: http://www.msascodesignsolutions.com/thankyou.html');

?>
这是最好、最干净的解决方案。基于您提供的PHP脚本,我看不出有任何失败的原因。但是,如果出于某种原因,您收到如下消息:

警告:无法修改标题信息-标题已发送

你可以考虑在你的HTML中嵌入JavaScript中的重定向,比如:

<!-- include your own success html here -->
<script type="text/javascript">
    window.location = "http://www.msascodesignsolutions.com/thankyou.html"
</script>

window.location=”http://www.msascodesignsolutions.com/thankyou.html"

这是一个比仅使用PHP更糟糕的解决方案,但它将使您不必对PHP进行更重要的更改。

我通常重定向的方式是添加$redirect变量,然后在脚本运行结束时调用该变量。例如:在页面或脚本的最顶端添加

$redirect = header('Location: fileNameOfPageYouWantToRedirectTo.php');
这必须是运行的第一件事,否则它将创建一个错误,这是我所经历的

然后运行脚本,在脚本结束时,在关闭查询之前调用以下变量。我只想将“thankyou”页面文件名添加到顶部提交的头函数中

$redirect;

但是,这将不允许您添加诸如“form was submitted”(表单已提交)之类的消息,因为它将在消息在脚本中发出之前重定向,或者更好地说,如果消息已创建,则重定向速度将非常快,以至于访问者无法看到它(完全跳过),因为您正在重定向到感谢页面,您已经准备好了,无需担心Javascript。如果要为多个表单使用公共文件进行提交,并根据当前链接更改重定向链接,则还可以选择动态生成重定向链接。如果您想重用它,我认为它会更有效。

这是您的整个PHP脚本吗?没有什么好建议的,谢谢你联系我们。我们将很快与您联系。将永远不会出现。您的右侧,它已被切断。抱歉…其//创建电子邮件标题$headers='From:'。$email\u From.\r\n''答复:'.$email\u from.\r\n''X-Mailer:PHP/”。phpversion()@邮件($email_to,$email_subject,$email_message,$headers);?>感谢您联系我们。我们将很快与您联系。看起来你要成立一家名为“msascodesignsolutions”的公司,那么你不值得了解一些PHP吗?好的,我试试这个。非常感谢你!成功了!再次感谢你,亲爱的!我为你感谢上帝!愿上帝保佑,很高兴听到这个消息。你会接受答案作为你问题的答案吗(在分数下面打勾)?
$redirect;