简体   繁体   English

使用模板,重定向至“谢谢您”页面在我的PHP代码中不起作用

[英]The redirect to thank you page is not working in my PHP code, using template

I am new to PHP. 我是PHP新手。 I have been using this example from a website and the redirect to thank you page is not working, can anyone solve why? 我一直在通过网站使用此示例,“重定向至谢谢”页面无法正常工作,有人可以解决原因吗? Also I'm not getting the email to myself either, I have got the example code from: http://form.guide/email-form/html-email-form.html 另外,我也没有收到自己的电子邮件,我从以下网址获得了示例代码: http : //form.guide/email-form/html-email-form.html

After downloading the full code it just redirects to the PHP codes instead of going to the thank you page. 下载完整代码后,它仅重定向到PHP代码,而不是转到“谢谢”页面。

 if( empty($errors)) { $to = $myemail; $email_subject = "Contact form submission: $firstname"; $email_body = "You have received a new message. ". " Here are the details:\\n Name: $firstname \\n Email: $email_address \\n Message \\n $message"; $headers = "From: $myemail\\n"; $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); //redirect to the 'thank you' page header('Location: contact-form-thank-you.html'); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Contact form handler</title> </head> <body> <!-- This page is displayed only if there is some error --> <?php echo nl2br($errors); ?> </body> </html> 

You forgot: 你忘了:

<?php

in the first line of your code. 在代码的第一行。 Php interpreter doesn't understant where your code starts and you see php code as html. php解释器不会弄清楚您的代码从哪里开始,您会看到php代码为html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM